I've run into something that seems like a glitch, because the code and the test database are so simple that I can't fathom what could be wrong. I'm running a simple update query on a mySQL database, using PHP version 4.4.2 and mySQL 4.1.21-standard (my web host's, not my own):
[php]
$resetkey = (...some randomized string...);
$query = "UPDATE weblogins SET veristring='".$ resetkey."' WHERE email='".$_POST['email']."'";
$result = mysql_query($qu ery) or die('Query failed: ' . mysql_error());
if ($result){ ... }
[/php]
The email variable is "41test@test.co m"
Simple right? The problem I'm having is that there is only one record in that table, it has the email address "42test@test.co m", and PHP is updating its veristring field instead of finding no matching record and returning a -1 result.
In debugging this I had the query printed to screen to verify it:
UPDATE weblogins SET veristring='NcY ' WHERE email='41test@t est.com'
Totally perplexed, I copied that query and pasted it into the phpMyAdmin interface to test it directly, and it came back with no fields affected, as it should be. I then had it generate the php code for that query:
$query = 'UPDATE weblogins SET veristring=\'Nc Y\' WHERE email=\'41test@ test.com\'';
... stuck it back into my php code, and still it updates that record even though the email fields don't match. It seems php thinks that they're close enough... but this causes a problem.
I created this test specifically to test the error messages given to the user, but I have yet to see those messages because PHP keeps incorrectly updating this record.
wtf? Any thoughts? Is this a known problem fixed with a newer version of either software?
[php]
$resetkey = (...some randomized string...);
$query = "UPDATE weblogins SET veristring='".$ resetkey."' WHERE email='".$_POST['email']."'";
$result = mysql_query($qu ery) or die('Query failed: ' . mysql_error());
if ($result){ ... }
The email variable is "41test@test.co m"
Simple right? The problem I'm having is that there is only one record in that table, it has the email address "42test@test.co m", and PHP is updating its veristring field instead of finding no matching record and returning a -1 result.
In debugging this I had the query printed to screen to verify it:
UPDATE weblogins SET veristring='NcY ' WHERE email='41test@t est.com'
Totally perplexed, I copied that query and pasted it into the phpMyAdmin interface to test it directly, and it came back with no fields affected, as it should be. I then had it generate the php code for that query:
$query = 'UPDATE weblogins SET veristring=\'Nc Y\' WHERE email=\'41test@ test.com\'';
... stuck it back into my php code, and still it updates that record even though the email fields don't match. It seems php thinks that they're close enough... but this causes a problem.
I created this test specifically to test the error messages given to the user, but I have yet to see those messages because PHP keeps incorrectly updating this record.
wtf? Any thoughts? Is this a known problem fixed with a newer version of either software?
Comment