How can SQL injections be prevented in PHP code, specifically in the context of the UPDATE query shown in the forum discussion?

SQL injections can be prevented in PHP code by using prepared statements with parameterized queries. This ensures that user input is treated as data rather than executable code, thus preventing malicious SQL injection attacks.

// Assuming $conn is the database connection object

// Prepare the SQL statement with placeholders
$stmt = $conn->prepare("UPDATE users SET username = :username, password = :password WHERE id = :id");

// Bind parameters to the placeholders
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password', $password);
$stmt->bindParam(':id', $id);

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