Jump to content


if sql was executed successfully... display message

  • Please log in to reply
1 reply to this topic

#1 centenial

  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 10 June 2006 - 09:13 PM

Is there a way to do this?

If MySQL query was executed successfully - Display success message.

Else... Display error message.

There must be an easy way to do this, but I don't know how to tell the script if the query was executed successfully.

Please help?

#2 poirot

  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 10 June 2006 - 09:15 PM

$sql = "SELECT something FROM sometable";
$result = mysql_query($query);

if ($result === false) {
   echo 'Error: ' .mysql_error();
} else {
   echo 'Success';

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]For SELECT, SHOW, DESCRIBE or EXPLAIN statements, mysql_query() returns a resource on success, and FALSE on error.

For other type of SQL statements, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success and FALSE on error. [/quote]
~ D Kuang

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users