What are potential reasons for a server error 500 when running a MySQL update in PHP?

A server error 500 when running a MySQL update in PHP could be caused by syntax errors in the SQL query, incorrect database connection settings, or insufficient permissions to update the database. To solve this issue, check the SQL query for any errors, ensure that the database connection is properly established, and verify that the user has the necessary permissions to perform the update operation.

<?php
// Establish database connection
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Update query
$sql = "UPDATE table_name SET column_name = 'new_value' WHERE condition";

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

$conn->close();
?>