What are the common errors and troubleshooting steps when encountering SQL syntax errors in PHP scripts?

Common errors when encountering SQL syntax errors in PHP scripts include missing or incorrect quotation marks around strings, missing or incorrect SQL keywords, and incorrect table or column names. To troubleshoot these issues, carefully review the SQL query being executed and ensure that all syntax is correct. Example PHP code snippet:

// Incorrect SQL query with missing quotation marks
$sql = "SELECT * FROM users WHERE username = $username";

// Corrected SQL query with added quotation marks around the variable
$sql = "SELECT * FROM users WHERE username = '$username'";