What is the recommended approach for changing values in a database table using PHP?

When changing values in a database table using PHP, the recommended approach is to use SQL UPDATE queries. These queries allow you to specify which columns you want to update and set new values for those columns based on certain conditions.

<?php
// Connect to the database
$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 values in the database table
$sql = "UPDATE table_name SET column1 = 'new_value1', column2 = 'new_value2' WHERE condition";

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

// Close connection
$conn->close();
?>