Try echo out the $sql to see if it's ok.
PHP Code:
echo "<p>$sql</p>"
-Helge