What are the common pitfalls or misconceptions that PHP learners should be aware of when following code examples from external sources, and how can they avoid falling into these traps?

One common pitfall for PHP learners when following code examples from external sources is not properly sanitizing user input, which can lead to security vulnerabilities such as SQL injection attacks. To avoid this, 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 prevent SQL injection
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username');
$stmt->bindParam(':username', $username);
$stmt->execute();