What are some common pitfalls or misconceptions that beginners should be aware of when learning PHP?

One common pitfall for beginners learning PHP is not properly escaping user input, which can leave your application vulnerable to SQL injection attacks. To prevent this, always use prepared statements or parameterized queries when interacting with a database. Example:

// Incorrect way (vulnerable to SQL injection)
$user_input = $_POST['username'];
$query = "SELECT * FROM users WHERE username = '$user_input'";
$result = mysqli_query($connection, $query);

// Correct way (using prepared statements)
$user_input = $_POST['username'];
$query = "SELECT * FROM users WHERE username = ?";
$stmt = $connection->prepare($query);
$stmt->bind_param("s", $user_input);
$stmt->execute();
$result = $stmt->get_result();