How can one prevent SQL injection vulnerabilities in PHP scripts, specifically in the context of password change functionality?

To prevent SQL injection vulnerabilities in PHP scripts, specifically in the context of password change functionality, you should always use prepared statements with parameterized queries when interacting with the database. This ensures that user input is properly sanitized and prevents malicious SQL code from being executed.

// Connect to the database
$pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");

// Prepare a SQL statement with a parameterized query
$stmt = $pdo->prepare("UPDATE users SET password = :newPassword WHERE id = :userId");

// Bind parameters
$stmt->bindParam(':newPassword', $newPassword);
$stmt->bindParam(':userId', $userId);

// Execute the statement
$stmt->execute();