The first you should take is to print out your SQL statement to verify that it is constructed properly:
print $query . "\n";
The next thing that everyone should do is make use of the mysql_error() function:
print mysql_error() . "\n";
anytime that a query returns an error.
-Rich