What is the best practice for updating MySQL records when downgrading a user account in PHP?

When downgrading a user account in PHP, the best practice for updating MySQL records is to use a SQL query to update the user's account level to the desired lower level. This can be done by executing an UPDATE query with the appropriate WHERE clause to target the specific user account that needs to be downgraded.

<?php
// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

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

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

// Update user account level to downgrade
$user_id = 123; // User ID of the account to be downgraded
$new_level = "basic"; // Desired lower level for the account

$sql = "UPDATE users SET account_level = '$new_level' WHERE user_id = $user_id";

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

$conn->close();
?>