alexville Posted April 1, 2006 Share Posted April 1, 2006 Hello,I want to make an error message if someone guesses the wrong answer. How do I create a message if the query doesn't pass ("update anything")Thanks Quote Link to comment https://forums.phpfreaks.com/topic/6314-checking-if-query-has-passed-of-not/ Share on other sites More sharing options...
toplay Posted April 1, 2006 Share Posted April 1, 2006 Please read some MySQL tutorials. If you're new to PHP/MySQL please post in the newbie topic area instead.Basic example:[code]$sql = 'Update ....';$result = mysql_query($sql);if ($result) echo 'Row has been updated';else echo 'Could not update the row. Error: ', mysql_error();[/code]Look at the FAQ post at the top of the newbie topic area. Quote Link to comment https://forums.phpfreaks.com/topic/6314-checking-if-query-has-passed-of-not/#findComment-22802 Share on other sites More sharing options...
alexville Posted April 1, 2006 Author Share Posted April 1, 2006 It doesn't work with mine... Can you take a look at it?[code]mysql_select_db("alexg_web",$dbcnx);$resultupdateguess = @mysql_query("UPDATE whoamipeople SET guessed = '$newguessed' WHERE Firstname = '$guessfirstname'");[/code]If the data can NOT be updated (because the Firstnames dont match) i want it to show a message. Quote Link to comment https://forums.phpfreaks.com/topic/6314-checking-if-query-has-passed-of-not/#findComment-22804 Share on other sites More sharing options...
toplay Posted April 1, 2006 Share Posted April 1, 2006 I've already given you an example. Please try and apply what people share on this forum to you. Here's another:[code]// Connect to MySQL first!$dbcnx = mysql_connect('localhost', 'mysql_user', 'mysql_password');if (!$dbcnx) { die('Could not connect: ' . mysql_error());}$db_selected = mysql_select_db("alexg_web", $dbcnx);if (!$db_selected) { die ('Could not select DB: ' . mysql_error());}$resultupdateguess = mysql_query("UPDATE whoamipeople SET guessed = '$newguessed' WHERE Firstname = '$guessfirstname'");if ($resultupdateguess) echo 'Row has been updated';else echo 'Could not update the row. Error: ', mysql_error();[/code] Quote Link to comment https://forums.phpfreaks.com/topic/6314-checking-if-query-has-passed-of-not/#findComment-22806 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.