What potential pitfalls should be considered when retrieving user input from an input text field in PHP?

When retrieving user input from an input text field in PHP, it is important to consider potential security vulnerabilities such as SQL injection attacks and cross-site scripting (XSS) attacks. To prevent these issues, always sanitize and validate user input before using it in your application. Use functions like htmlspecialchars() to prevent XSS attacks and prepared statements to prevent SQL injection attacks.

// Sanitize and validate user input from an input text field
$userInput = $_POST['input_field'];

// Sanitize user input to prevent XSS attacks
$sanitizedInput = htmlspecialchars($userInput);

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