'Update mysql table data from xml file

Good morning, I ask you why I have a problem with a script in php to update the data of a mysql table.

I have a table with the following values:

id, name, city, city_id

and an xml file with the data to be updated:

id_city, city

I tried to make a script to update the data in the table, but unfortunately I always get errors.

My script is as follows:

<?php
$conn = mysqli_connect("localhost", "root", "", "dbtest001");


$affectedRow = 0;

$xml = simplexml_load_file("city.xml") or die("Error: Cannot create object");

foreach ($xml->children() as $row) {
    
    $id_city = mysqli_real_escape_string($conn, ($row-> id_city));
    $city = mysqli_real_escape_string($conn, ($row-> city));
    
        
    $sql = "UPDATE user_city SET (id_city, city)
    VALUES ('" . $id_city . "', '" . $city . "')
    ON DUPLICATE KEY UPDATE id_city=$id_city "
    ;
    
    
    $result = mysqli_query($conn, $sql);
    
    if (! empty($result)) {
        $affectedRow ++;
    } else {
        $error_message = mysqli_error($conn) . "\n";
    }
}
?>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source