One thing you should always be doing is checking the value returned by any query, and if it's 0, then have some way of echoing or printing the error to the browser (if you're developing) or (if it's production code) showing a nice "ooops, sorry, something messed up" message to the user and logging the error returned by the db.
e.g.
if (!$result = mysql_query($sql)) {
die("Error: " . mysql_error($db_handle));
}
This will cut down on those pesky "document contained no data" errors at least; if you rewrite your code (or if you already have something like this in place) and the problem persists, then post your problem here again with more info.
HTH
AC