How can the code structure and logic of the PHP script be improved to adhere to the E.V.A. principle and enhance overall security?

Issue: The PHP script lacks proper validation and sanitization of user input, which can lead to security vulnerabilities such as SQL injection or cross-site scripting attacks. Solution: To adhere to the E.V.A. principle (Escape, Validate, and Avoid), all user input should be properly validated and sanitized before being used in the script. This can be done by using functions like filter_input() or prepared statements to prevent malicious input from affecting the application.

$user_input = filter_input(INPUT_POST, 'user_input', FILTER_SANITIZE_STRING);

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