How can the SQL syntax error related to the UPDATE function in PHP be resolved?

When encountering a SQL syntax error related to the UPDATE function in PHP, it is usually due to incorrect formatting of the SQL query. To resolve this issue, make sure the UPDATE query is properly structured with the correct table name, column names, and values to update. Additionally, ensure that any variables or values being passed into the query are properly sanitized to prevent SQL injection attacks.

<?php
// Assuming $conn is the database connection object

// Example of a correct UPDATE query
$id = 1;
$newValue = "Updated Value";

$sql = "UPDATE table_name SET column_name = '$newValue' WHERE id = $id";

if ($conn->query($sql) === TRUE) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . $conn->error;
}

$conn->close();
?>