What potential pitfalls should be avoided when using PHP for user input forms?

One potential pitfall to avoid when using PHP for user input forms is not properly sanitizing and validating user input, which can lead to security vulnerabilities such as SQL injection or cross-site scripting attacks. To prevent this, always sanitize and validate user input before using it in your application.

// Sanitize and validate user input
$username = htmlspecialchars($_POST['username']);
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);