What potential security risks are involved in directly updating database values based on user input in PHP?

Directly updating database values based on user input in PHP can lead to SQL injection attacks, where malicious users can manipulate the input to execute unauthorized SQL commands. To mitigate this risk, it is important to use prepared statements or parameterized queries to sanitize and validate user input before updating the database.

// Using prepared statements to update database values based on user input
$stmt = $pdo->prepare("UPDATE users SET email = :email WHERE id = :id");
$stmt->bindParam(':email', $email);
$stmt->bindParam(':id', $id);
$stmt->execute();