What common syntax errors can occur when using PHP and MySQL together?

One common syntax error when using PHP and MySQL together is not properly escaping strings before inserting them into a query, which can lead to SQL injection vulnerabilities. To solve this issue, you should use prepared statements or parameterized queries to sanitize user input.

// Example of using prepared statements to avoid SQL injection
$stmt = $pdo->prepare("INSERT INTO users (username, password) VALUES (:username, :password)");
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password', $password);
$stmt->execute();