How to identify a MySQL query problem

Sometimes you happen to have a problem with one of your MySQL queries and you simply can’t seem to understand why.

Well, one thing that helps is to use the mysql_error() function.

This function returns the message of the MySQL error you’re getting.

Example:

$action = “INSERT INTO table (name, address, dob) VALUES (‘$name’, ‘$address’, ‘$dob’)”;
$query = mysql_query($action) or die(mysql_error());

If we happen to get a problem with our MySQL error the script execution will stop (by using the die() function) and the MySQL error message will be returned (by using the mysql_error() function).

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.