You don't need to prevent this error message!
Error messages are your friends!
Without error message you'd never know what is happened.
It's all right! Any working code supposed to throw out error messages.
Though error messages needs proper handling.
Usually you don't have to to take any special actions to avoid such an error messages. Just leave your code intact.
But if you don't want this error message to be shown to the user, just turn it off. Not error message itself but daislaying it to the user.
ini_set('display_errors',0);
ini_set('log_errors',1);
or even better at .htaccess/php.ini level
And user will never see any error messages. While you will be able still see it in the error log.
Please note that error_reporting should be at max in both cases.
To prevent this message you can check mysql_query result and run fetch_assoc only on success.
But usually nobody uses it as it may require too many nested if's.
But there can be solution too - exceptions!
But it is still not necessary. You can leave your code as is, because it is supposed to work without errors when done.
Using return
is another method to avoid nested error messages. Here is a snippet from my database handling function:
$res = mysql_query($query);
if (!$res) {
trigger_error("dbget: ".mysql_error()." in ".$query);
return false;
}
if (!mysql_num_rows($res)) return NULL;
//fetching goes here
//if there was no errors only