What are the potential security risks associated with the current implementation of the PHP script, and how can they be mitigated to protect against vulnerabilities?

The potential security risks associated with the current implementation of the PHP script include SQL injection attacks and cross-site scripting (XSS) vulnerabilities. To mitigate these risks, it is important to use prepared statements for database queries and sanitize user input to prevent malicious code execution.

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

// Sanitizing user input to prevent XSS vulnerabilities
$username = htmlspecialchars($_POST['username']);