A thing that is very usefull when writng in/retreaving info from a SQL-database is: write the sql-statement( $sql="SELECT *...), and then run it(mysql_result($sql)) THEN:
Write out $sql-variable to screen, and see if you can see any obveous mistakes, you can also copy the sql-statement outputted in the browser, and run it directly in MySQL, there you get better error-reporting, unless you use the php-mysql-error-functions.
This is something I always do when I am developting PHP/MySQL-scripts...
Good luck!