What is the correct syntax for updating a MySQL database using a variable in PHP?

When updating a MySQL database using a variable in PHP, you need to concatenate the variable within the SQL query string. This ensures that the variable value is properly inserted into the query. Make sure to sanitize and validate the variable to prevent SQL injection attacks.

// Assuming $conn is the MySQL database connection object and $value is the variable to be updated
$value = "new_value";
$value = mysqli_real_escape_string($conn, $value); // Sanitize the variable

$sql = "UPDATE table_name SET column_name = '$value' WHERE condition";
if(mysqli_query($conn, $sql)){
    echo "Record updated successfully";
} else{
    echo "Error updating record: " . mysqli_error($conn);
}