Jump to content

Archived

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

alexville

Checking if query has passed of not

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

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.