Jump to content

enrb15

New Members
  • Posts

    1
  • Joined

  • Last visited

enrb15's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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"; } } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.