What are common pitfalls to watch out for when using PHP in web development?
One common pitfall in PHP web development is not properly sanitizing user input, which can lead to security vulnerabilities such as SQL injection or cross-site scripting attacks. To prevent this, always use prepared statements when interacting with databases and validate and sanitize user input before using it in your code.
// Example of using prepared statements to prevent SQL injection
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username');
$stmt->execute(['username' => $username]);
```
```php
// Example of sanitizing user input
$username = filter_var($_POST['username'], FILTER_SANITIZE_STRING);
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);