How can the PHP code be modified to ensure that only specific rows are updated in the database?

To ensure that only specific rows are updated in the database, you can use a WHERE clause in your SQL query to specify the conditions that the rows must meet in order to be updated. This way, only the rows that match the specified conditions will be affected by the update operation.

<?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 specific rows in the database
$sql = "UPDATE table_name SET column1 = 'new_value' WHERE condition_column = 'condition_value'";

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

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