View Single Post
Old 06-21-2011, 10:09 AM   PM User | #3
bullant
Banned

 
Join Date: Feb 2011
Posts: 2,699
Thanks: 13
Thanked 395 Times in 395 Posts
bullant is on a distinguished road
Quote:
Originally Posted by tangoforce View Post
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:
PHP 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.

Last edited by bullant; 06-21-2011 at 10:11 AM..
bullant is offline   Reply With Quote