Jump to content


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


if sql was executed successfully... display message

Recommended Posts

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?

Share this post

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

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.