What are some common pitfalls to avoid when starting a PHP project as a beginner?

One common pitfall for beginners is not properly sanitizing user input, leaving the project vulnerable to security risks like SQL injection attacks. To avoid this, always use prepared statements when interacting with a database to prevent malicious input from being executed as code.

// Example of using prepared statements to sanitize user input
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username');
$stmt->bindParam(':username', $username);
$stmt->execute();
$results = $stmt->fetchAll();