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?
Link to comment
Share on other sites

[!--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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.