Originally Posted by tangoforce
Many new PHP coders will come across this error and will be a bit confused by what it means so I thought I would supply a quick topic to cover the issue in more detail.
Lets suppose we have the following code:
$sql = "INSERT INTO wall (author, message) VALUES ("' .$author. '", "'. $message. '")";
That is one line of PHP containing an SQL statement. To the experienced eye its defective but to a lot of new PHP programmers this looks fine.
More often than not, when a query is not returning the results you expect, there is a syntax error in the query itself.
I find the easiest and quickest way to check what the actual query about to be run is, is to echo it to the browser and syntax errors should then be fairly obvious.
For more complex queries a good practice imo is to first get the query working in the SQL GUI of your choice and then transfer the query to your server side script.
Debugging an sql statement in an sql gui is usually a lot easier than trying to debug it in the server side script.