What is the correct syntax for updating SQL records in PHP using prepared statements?

When updating SQL records in PHP using prepared statements, it is important to properly bind parameters to prevent SQL injection attacks. To do this, you need to create a SQL UPDATE statement with placeholders for the values to be updated, then bind the parameters using the bind_param method. Finally, execute the prepared statement to update the records in the database.

// Assuming $conn is your database connection

// Prepare an SQL UPDATE statement with placeholders
$sql = "UPDATE table_name SET column1 = ?, column2 = ? WHERE id = ?";

// Prepare the statement
$stmt = $conn->prepare($sql);

// Bind parameters
$stmt->bind_param("ssi", $value1, $value2, $id);

// Set the values of the parameters
$value1 = "new_value1";
$value2 = "new_value2";
$id = 1;

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

// Close the statement and connection
$stmt->close();
$conn->close();