Jump to content

Checking if data in database was updated from a query


alexville

Recommended Posts

I've been trying for days to get this too work.. I need help with this code: [code]mysql_select_db("alexg_web",$dbcnx);
$updatesql = "UPDATE whoamipeople SET guessed = '$newguessed' WHERE id = '$guessid'";
$resultupdateguess = mysql_query($updatesql, $dbcnx);
if (!$resultupdateguess) {
   echo "Sorry! That guess was incorrect. Nice Try!\n";
   echo 'MySQL Error: ' . mysql_error();
   exit;
}[/code]

If no data is updated because the id doesn't match the guessed id in the database... I want it to display this message. [code]if (!$resultupdateguess) {
   echo "Sorry! That guess was incorrect. Nice Try!\n";
   echo 'MySQL Error: ' . mysql_error();
   exit;
}[/code]

But that code doesn't work! what am i doing wrong?
[!--quoteo(post=360602:date=Apr 1 2006, 02:41 PM:name=alexville)--][div class=\'quotetop\']QUOTE(alexville @ Apr 1 2006, 02:41 PM) [snapback]360602[/snapback][/div][div class=\'quotemain\'][!--quotec--]
But that code doesn't work! what am i doing wrong?
[/quote]

You are assuming that the query failed just because there is no record with id = $guessid.

The query will only fail and return false if there is an error. Not finding a record does not constitute an error.

Try
[code]
if (mysql_affected_rows($resultupdateguess) == 0) {
     echo "Sorry! That guess was incorrect. Nice Try!\n";
}[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.