If $result is not a valid MySQL result resource, that means that the query did not return a resource but false, so your query failed.
You should not suppress the error message or at least check for the result of the query to not be false before you proceed using the results:
if (!$result)
{
// error
}
else
{
// use results
}