What are the best practices for handling errors in PHP's mysql_query() function?

When using the mysql_query() function in PHP, it is important to handle errors properly to prevent potential security vulnerabilities and ensure the stability of your application. One best practice is to check the return value of mysql_query() for errors and handle them accordingly by using functions like mysql_error(). Additionally, it is recommended to sanitize user input to prevent SQL injection attacks.

$query = "SELECT * FROM users";
$result = mysql_query($query);

if(!$result) {
    die('Error: ' . mysql_error());
}

// Continue processing the query result here