title: Insert XML Data to MySQL Table Using PHP
body: <p>I am trying to insert xml data to my sql but it is not inserting. how to write the foreach(xml->) for this type of xml.the xml is generated dynamically in this structure.this is a sample xml in this format</p>
  
  <pre><code>&lt;?php
  $xmlData =&lt;&lt;&lt; END
  &lt;?xml version="1.0"?&gt;
  &lt;Customer&gt;
  &lt;id&gt;1&lt;/id&gt;
  &lt;name&gt;Oluwafemi&lt;/name&gt;
  &lt;address&gt;Cresent Drive, TX&lt;/address&gt;
  &lt;list&gt;
  &lt;contact&gt;56689&lt;/contact&gt;
  &lt;telephone&gt;5889745&lt;/telephone&gt;
  &lt;/list&gt;
  &lt;offer&gt;congrats&lt;/offer&gt;
  &lt;/Customer&gt;
  END;
  
  $xml = simplexml_load_string($xmlData) or die("ERROR: Cannot create SimpleXML object");
  $connection = mysqli_connect("localhost", "root", "", "Customers") or die ("ERROR: Cannot connect");
  
  foreach ($xml-&gt;Customer as $Customer) {
  $id = $Customer-&gt;id;
  echo "$id";
  $name =  $Customer-&gt;name;
  $address = $Customer-&gt;address;
  
  $sql = "INSERT INTO customerdata (id, name, address ) VALUES ('$id', '$name', '$address')";
  mysqli_query($connection, $sql) or die ("ERROR: " .mysqli_error($connection) . " (query was $sql)");
  }
  mysqli_close($connection);
  ?&gt;
  </code></pre>