in reply to Re: Persistent database connections show incorrect results
in thread Persistent database connections show incorrect results

Thanks for the respones.
Yes I mean lexical .
I tried running httpd -X, and then it happens immediately ie: the second time I submit the form it has the values from the first time.

Here is the code.

use strict vars; use CGI qw(param); use diagnostics ; # Constants my $db = "ecreditdb"; my $server = "localhost"; my $user = "updater"; my $password = "1q2w3e4r"; # CGI Parameters my $Id = param("ID"); my $Fname = param("Fname"); sub init { # Connect to database my $dbh = ''; $dbh = DBI->connect("DBI:mysql:$db:$server", $user,$password); if (! $dbh) { print "Could not connect to $db on $server\n"; } $dbh->{RaiseError} = 1; # Prepare and run the query my $query="INSERT INTO clients values( \"$Fname\",\"$Id\") ;"; my $sth = $dbh->prepare_cached("$query") or die "Can't prepare stateme +nt: $dbh->errstr \n"; $sth->execute or die "Can't execute statement", $dbh->errstr ; $sth->finish; $dbh->disconnect(); disp(); } # End sub disp { print " <html> <head> <title>Update completed successfully</title> </head> <body bgcolor=\"#CCCCCC\"> <p align=\"center\"><font face=\"Courier New\" size=\"4\"><b><br> <font color=\"#000000\">Update completed successfully</font></b></font +></p> <p align=\"center\">&nbsp;</p> <p align=\"center\"> <b><font color=\"#8000000\">Please logon again !! </font></b></p> <p align=\"center\">&nbsp;</p> <p align=\"center\"> <a href=\"/private/login.htm\">Press here to logon</a></p> </body> </html> "; } init();


Thanks

Replies are listed 'Best First'.
Re: Re: Re: Persistent database connections show incorrect results
by perrin (Chancellor) on Apr 17, 2002 at 20:34 UTC
    You have am unintentional closure, created by using subroutines that refer to lexicals declared outside their scope. This is a known problem with Apache::Registry (but not with standard mod_perl handlers written to the mod_perl API). You can fix it by moving the CGI parameter code inside the init sub.

    For more on this topic, see the guide. Also, turn on warnings use full strict (not just vars) to catch this sort of problem.

      Hi Perrin

      That solved it, it makes sense now.

      Thanks a million!
      Paul