Jump to content


Photo

Checking if query has passed of not


  • Please log in to reply
3 replies to this topic

#1 alexville

alexville
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 01 April 2006 - 02:27 AM

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

#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 01 April 2006 - 02:32 AM

Please read some MySQL tutorials. If you're new to PHP/MySQL please post in the newbie topic area instead.

Basic example:
$sql = 'Update ....';
$result = mysql_query($sql);

if ($result)
   echo 'Row has been updated';
else
   echo 'Could not update the row. Error: ', mysql_error();

Look at the FAQ post at the top of the newbie topic area.

#3 alexville

alexville
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 01 April 2006 - 02:48 AM

It doesn't work with mine... Can you take a look at it?

mysql_select_db("alexg_web",$dbcnx);
$resultupdateguess = @mysql_query("UPDATE whoamipeople SET guessed = '$newguessed' WHERE Firstname = '$guessfirstname'");

If the data can NOT be updated (because the Firstnames dont match) i want it to show a message.

#4 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 01 April 2006 - 03:08 AM

I've already given you an example. Please try and apply what people share on this forum to you. Here's another:

// 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();





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users