What are common pitfalls when validating form input using PHP?

One common pitfall when validating form input using PHP is not properly sanitizing user input, which can lead to security vulnerabilities such as SQL injection or cross-site scripting attacks. To solve this issue, always sanitize user input using functions like htmlspecialchars() or mysqli_real_escape_string() before processing or storing it in the database.

// Example of sanitizing user input using htmlspecialchars()
$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);
```

Another common pitfall is not validating input data properly, which can result in unexpected behavior or errors in your application. To solve this issue, always validate user input against expected formats or values using functions like filter_var() or regular expressions.

```php
// Example of validating email input using filter_var()
$email = $_POST['email'];
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo "Invalid email format";
}