How can the mysql_error() function be utilized to troubleshoot SQL syntax errors in PHP?

The mysql_error() function in PHP can be utilized to retrieve the error message generated by MySQL when there is a syntax error in an SQL query. By capturing and displaying this error message, developers can quickly identify and troubleshoot the syntax error in their SQL query.

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

if(!$result) {
    echo "Error: " . mysql_error();
}