Couple of things you can try that can save you a ton of frustration in the long run:
Include something like this after each database hit:
or die ("<p>" . mysql_errno() . ": " . mysql_error() . "<p>");
(example)
$mysql_link = mysql_connect
('localhost', 'root' , '')
or die ("Connection failed!<p>".
mysql_errno().": ".mysql_error());
mysql_select_db('test')
or die ("Could not connect to db!<p>".
mysql_errno().": ".mysql_error());
$result=mysql_query($sql)
or die ("Sql prob:".$sql."<p>".
mysql_errno().": ".mysql_error());
After the final one add a line like this, using your variable for the sql statement instead of $sql:
echo "<p>".$sql."<p>".
mysql_errno() . ": " . mysql_error()
. "<p>";