What are common syntax errors in SQL queries when using PHP and MySQL?

One common syntax error in SQL queries when using PHP and MySQL is forgetting to properly escape strings in the query, which can lead to SQL injection vulnerabilities. To solve this issue, always use prepared statements or parameterized queries to safely pass user input to the database.

// Example of using prepared statements to prevent SQL injection
$pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");

$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $_POST['username']);
$stmt->execute();