What are the common syntax errors that can occur when writing PHP code for SQL queries?

One common syntax error when writing PHP code for SQL queries is forgetting to properly concatenate variables within the query string. This can lead to errors or unexpected behavior when executing the query. To solve this issue, make sure to properly concatenate variables using the dot (.) operator within the query string.

// Incorrect way of concatenating variables in SQL query
$query = "SELECT * FROM users WHERE username = $username"; 

// Correct way of concatenating variables in SQL query
$query = "SELECT * FROM users WHERE username = '" . $username . "'";