What are the potential pitfalls of incorrect SQL syntax in a PHP script?

Incorrect SQL syntax in a PHP script can lead to errors such as syntax errors, database connection failures, or unexpected results. To avoid these pitfalls, it is important to double-check SQL queries for accuracy and use prepared statements to prevent SQL injection attacks.

// Incorrect SQL syntax example
$sql = "SELECT * FROM users WHERE username = $username"; // Missing quotes around $username

// Corrected SQL syntax using prepared statements
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $username);
$stmt->execute();