|No such thing as a small change|
Re: Editing data extracted from mysql through CGI/mod_perlby Arguile (Hermit)
|on Jun 10, 2002 at 18:59 UTC||Need Help??|
Your subroutines are constantly acting on globals. This makes it very hard to debug anything, you also need to see the entire script in that case. With mod_perl you also need to remeber that Perl is persistant, check the guide to see how this can effect you. Something along the lines of:
Would make everything much easier to debug. You don't have to worry about passing $dbh by copy as it's a reference already (a concern that seems to come up often). As you can see, the only variables the subroutine works on is those passed into it.
You need to read up on DBI a bit more.
Look at the above. You disconnect, thereby destructing the handle, then try to use it in the next line. If you're using Apache::DBI this may not even cause an error as it overides the $dbh->disconnect method. It's certaintly not what you meant though.
You declare RaiseError => 1 then consistantly check for errors manually anways (sort of defeats the purpose no?).
At best this would only change the article title, not the body or any other part. And where do the variables come from? Pass them into the sub and check to make sure they're what you expect with a print statement or two.
Why do you declare connections in each sub? You're setting yourself up for errors due to inconsistancy. You many want to consider a generalised connection method.
You may want to check out CGI::Application; it's a framework that uses dispatch tables, similar to the way you seem to be setting up your scripts.
Most of these are generalised suggestions but, by taking some of them into account, I think you'll find most of your troubles go away and the ones that don't will be easier to debug.