Come one! Is there no one else here besides me disturbed by the fact that Neil is blindly using the query result w/o checking if it failed? The starting part should read something like this:
if (! ($result=mysql_query($sql)))
die("It's the end of the world as we know it: $php_errormsg");
else
{ // go ahead and read the result data
...
}
Kernighan and Plauger wrote way, way back in Software Tools about putting in error messages for "impossible to happen" conditions, and how embarrassingly often the "can't happen" messages showed up during development anyway, but I guess maybe nobody reads the computer engineering classics any more...