in reply to Re^2: keeping variables separate
in thread keeping variables separate

I think it's not so much the $r object and its params, but rather some other data structure that's retaining the values.  At least, in your original post, it isn't clear where %ship_address comes from, how data gets into it, if it's global (which could be the problem), or if you do empty it on every request, etc.  In other words, it's hard to provide anything else than general hints without seeing the actual (complete) code...

Replies are listed 'Best First'.
Re^4: keeping variables separate
by RandomWalk (Beadle) on Apr 20, 2009 at 18:50 UTC
    Thanks for your patience. I'll abstract: Perl handler to capture form submission data:
    sub handler { my $r = Apache2::Request->new(shift); my %in_cookies = Apache2::Cookie->fetch ($r); my $session = $in_cookies{"ID"} && $in_cookies{"ID"}->value; my $dbh = DBI->connect('DBI:mysql:mydb', 'myuser', 'mypasswd', { Ra +iseError => 1, AutoCommit => 1, PrintError => 1} ) or die $DBI::errst +r; my $shipaddr1 = $r->param("shipaddr1"); my $shipaddr2 = $r->param("shipaddr2"); my %ship_address = (addr1 => $shipaddr1, addr2 => $shipaddr2); unless ($dbh->selectrow_array("select count(*) from bill where sess +ion=?",undef,$session)){ # new entry $dbh->do("insert into bill (session) values(?)",undef,$session); while ( my ($key,$value) = each %ship_address ) { $dbh->do("update bill set ship$key = ? where session = ?", un +def, $value, $session); } }
    Difficulty: if the form does not contain data for shipaddr2 then shipaddr2 can contain data from a previous call to the handler.

      That %ship_address handling looks fine, AFAICT.

      if the form does not contain data for shipaddr2 then shipaddr2 can contain data from a previous call to the handler.

      How exactly did you check? Something like this

      ... my $shipaddr2 = $r->param("shipaddr2"); print STDERR "$shipaddr2\n";

      or just by observing that an unexpected value had made it into the DB table? If it's already the lexical $shipaddr2 containing some previous value (when "shipaddr2" isn't in the form/HTTP request), I'd say the problem is with libapreq2/Apache2::Request. At least it would narrow things down...