#!/usr/local/bin/perl -wT
use strict; use CGI ':standard'; use DBI; use CGI::Carp qw(fatalsToBrowser);
# Simulate a param call in CGI
my $player="HarryPotter";
# Connect to the database
my $dbh = DBI->connect("DBI:mysql:ladderDB", "xxxx", "xxxxxx");
# Make an update that is representative of the full script
my $offset=8;
my $updatehandle1 = $dbh->do("UPDATE league SET status = 1, available =
DATE_ADD(NOW(), INTERVAL '$offset' DAY) WHERE user_name = '$player'");
# Try to select the new value of available
my $availquery = "SELECT available FROM league WHERE user_name=$player";
The fact that you don't have single quotes around $player is highly
suspicious. I don't see any error checking. Make sure you have RaiseError
turned on.
Cut and paste error on my part. This was the first version of the minimised script, not the one that worked. Sorry about that.
Just run again with RaiseError put back in (I stripped out all the "dies" for this minimal example) same result.
I strongly suggest you use placeholders rather than interpolating values
directly into the query.
Yes, the "real script" does use placeholders, but since this is just a minimised version I tried to use the fewest lines approach.
Have you done what I suggested and constructed a minimal example to make
sure the database is working correctly?
This is about as minimal as I can get it and still show the logic in the code. Basically grab some stuff from the triggering page, run some script to decide what to do with the data, then perform the update that should set the available field letting mySQL do the sums, then call back the result of the date arithmetic. I've left one of the UPDATEs in in full to show that it is basically a very simple transaction.
The database is behaving itself, the fields really do get updated correctly, but I can't see why the change doesn't commit until the script exits.
my $availhandle=$dbh->prepare($availquery); $availhandle->execute; my($before) = $availhandle->fetchrow_array; # Full version selects email addresses etc in this block $availhandle->finish;
# See what came out into $before
print "Content-Type: text/html\n\n";
print "Query return is $before";# Always prints todays date. Expected return is today + 8
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]