I debug sql queries by these methods... 1) echo the sql to a browser so I can test in the Mysql Query Browser to make sure that all variables are set as expected and the query is good. I also include page, line # and the mysql error message in the die command. So if any query is bad you will know where and what and why (<--most of the time). example:
$sql = "select uid from users where uname='".$user_name."'";
$rst = mysql_query($sql) or die("
PG: ".__FILE__."
LN: ".__LINE__."
ER: ".mysql_error()."
Q: ".$sql."
");
Note: I usually do this as a function call inside the die so I can set a value for local debug and a live production messages. This is because the above information should be used for the developer and not something a user should ever see. Users should have a simple error message if you can not recover from the error in code. 2) if your code crashes out after the mysql_query, then find out what you query is returning...exactly. example:
That should give you more info. Also keep in mind that if you develope on windows and move to linux you will see some error with the case of table and column names make sure you check that. Windows can be lax on case, while linux is not.
Chris J www.redash.org