What are some common pitfalls to avoid when working with PHP forms and user input?

One common pitfall to avoid when working with PHP forms and user input is failing to properly sanitize and validate user input, which can leave your application vulnerable to security risks such as SQL injection or cross-site scripting attacks. To mitigate this risk, always sanitize and validate user input before using it in your application.

// Sanitize and validate user input
$username = isset($_POST['username']) ? htmlspecialchars($_POST['username']) : '';
$email = isset($_POST['email']) ? filter_var($_POST['email'], FILTER_SANITIZE_EMAIL) : '';
```

Another common pitfall is not using prepared statements when interacting with a database, which can expose your application to SQL injection attacks. To prevent this, always use prepared statements when executing SQL queries that include user input.

```php
// Using prepared statements to prevent SQL injection
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username');
$stmt->bindParam(':username', $username);
$stmt->execute();