alexville Posted April 1, 2006 Share Posted April 1, 2006 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 https://forums.phpfreaks.com/topic/6331-checking-if-data-in-database-was-updated-from-a-query/ Share on other sites More sharing options...
Barand Posted April 1, 2006 Share Posted April 1, 2006 [!--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 https://forums.phpfreaks.com/topic/6331-checking-if-data-in-database-was-updated-from-a-query/#findComment-22937 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.