What are common pitfalls to avoid when using PHP syntax and functions in code?

One common pitfall to avoid when using PHP syntax and functions is not properly escaping user input before using it in SQL queries, which can lead to SQL injection attacks. To solve this issue, always use prepared statements or parameterized queries when interacting with a database to prevent malicious input from being executed as SQL code.

// Example of using prepared statements to avoid SQL injection
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $username);
$stmt->execute();