title: Insert xml into sql with sql with foreach?
body: <p>First thing first, I have an xml feed from unibet.com that looks like this:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;betOfferResponse&gt;
      &lt;events&gt;
          &lt;name&gt;Red Star Belgrade - CSKA Moscow&lt;/name&gt;
          &lt;homeName&gt;Red Star Belgrade&lt;/homeName&gt;
          &lt;awayName&gt;CSKA Moscow&lt;/awayName&gt;
          &lt;start&gt;2018-02-13T17:00Z&lt;/start&gt;
          &lt;group&gt;Europa League&lt;/group&gt;
          &lt;type&gt;ET_MATCH&lt;/type&gt;
          &lt;sport&gt;FOOTBALL&lt;/sport&gt;
          &lt;state&gt;NOT_STARTED&lt;/state&gt;
          &lt;liveBetOffers&gt;true&lt;/liveBetOffers&gt;
          &lt;openForLiveBetting&gt;false&lt;/openForLiveBetting&gt;
          &lt;id&gt;1004394826&lt;/id&gt;
          &lt;groupId&gt;2000051195&lt;/groupId&gt;
          &lt;path&gt;
              &lt;id&gt;1000093190&lt;/id&gt;
              &lt;name&gt;Football&lt;/name&gt;
              &lt;englishName&gt;Football&lt;/englishName&gt;
          &lt;/path&gt;
          &lt;path&gt;
              &lt;id&gt;2000051195&lt;/id&gt;
              &lt;name&gt;Europa League&lt;/name&gt;
              &lt;englishName&gt;Europa League&lt;/englishName&gt;
          &lt;/path&gt;
      &lt;/events&gt;
      &lt;events&gt;
          &lt;name&gt;FC Astana - Sporting Lisbon&lt;/name&gt;
          &lt;homeName&gt;FC Astana&lt;/homeName&gt;
          &lt;awayName&gt;Sporting Lisbon&lt;/awayName&gt;
          &lt;start&gt;2018-02-15T16:00Z&lt;/start&gt;
          &lt;group&gt;Europa League&lt;/group&gt;
          &lt;type&gt;ET_MATCH&lt;/type&gt;
          &lt;sport&gt;FOOTBALL&lt;/sport&gt;
          &lt;state&gt;NOT_STARTED&lt;/state&gt;
          &lt;liveBetOffers&gt;true&lt;/liveBetOffers&gt;
          &lt;openForLiveBetting&gt;false&lt;/openForLiveBetting&gt;
          &lt;id&gt;1004394832&lt;/id&gt;
          &lt;groupId&gt;2000051195&lt;/groupId&gt;
          &lt;path&gt;
              &lt;id&gt;1000093190&lt;/id&gt;
              &lt;name&gt;Football&lt;/name&gt;
              &lt;englishName&gt;Football&lt;/englishName&gt;
          &lt;/path&gt;
          &lt;path&gt;
              &lt;id&gt;2000051195&lt;/id&gt;
              &lt;name&gt;Europa League&lt;/name&gt;
              &lt;englishName&gt;Europa League&lt;/englishName&gt;
          &lt;/path&gt;
      &lt;/events&gt;
  </code></pre>
  
  <p>but when I use my script for reading and putting the xml data into my db, it does not work, because of these: </p>
  
  <pre><code> &lt;betOfferResponse&gt;
  </code></pre>
  
  <p>But when I create my own xml with only the data underneath, it works. But it cant loop the file and get the second entry and so on.. </p>
  
  <p>Here is my php code that: </p>
  
  <pre><code>    &lt;?php
  
  
  $xml=simplexml_load_file("test.xml") or die("Error: Cannot create object");
  $connection = mysqli_connect("localhost", "root", "password", "tipstr") or die ("ERROR: Cannot connect");
  
  /* Assumes that the number of IDs = number of customers */
  $size = sizeOf($xml-&gt;id);
  $i = 0; //index
  
  /* Add each customer to the database, See how we reference it as    $xml-&gt;ENTITY[INDEX] */
  while($i != $size) 
  {
      print_r($xml);
      echo $xml-&gt;id[$i]; //Test
  
      $sql = "INSERT INTO xf_nflj_sportsbook_event (event_id, category_id, user_id, username, title, description, event_status, date_create, date_open, date_close, date_settle, date_edit, event_timezone, wagers_placed, amount_staked, amount_paidout, likes, like_users, view_count, outcome_count, comment_count, thread_id, prefix_id, last_comment_date, limit_wagers_single_outcome) VALUES ('$xml-&gt;id',2,1,'tipstr', '$xml-&gt;name', '$xml-&gt;sport', 'open', 1517755596,1517755596,1517761200,1517761200,0,'Europe/London', 0, 0,0,0,0,0,0,0,0,0,0,0)";
      mysqli_query($connection, $sql) or die ("ERROR: " .mysqli_error($connection) . " (query was $sql)");
  
      $i++; //increment index
  }
  
  
  mysqli_close($connection);
  </code></pre>
  
  <p>What am I doing wrong? How can I loop/foreach the insert query, so that it can get the whole file and not only the first one, and how can I make it read the xml from unibet? </p>
  
  <p>edit:
  Sorry about not adding the xml I use when I succeed. But here it is: </p>
  
  <pre><code> &lt;events&gt;
          &lt;name&gt;Marseille - S.C. Braga&lt;/name&gt;
          &lt;homeName&gt;Marseille&lt;/homeName&gt;
          &lt;awayName&gt;S.C. Braga&lt;/awayName&gt;
          &lt;start&gt;2018-02-15T18:00Z&lt;/start&gt;
          &lt;group&gt;Europa League&lt;/group&gt;
          &lt;type&gt;ET_MATCH&lt;/type&gt;
          &lt;sport&gt;FOOTBALL&lt;/sport&gt;
          &lt;state&gt;NOT_STARTED&lt;/state&gt;
          &lt;liveBetOffers&gt;true&lt;/liveBetOffers&gt;
          &lt;openForLiveBetting&gt;false&lt;/openForLiveBetting&gt;
          &lt;id&gt;1004394835&lt;/id&gt;
          &lt;groupId&gt;2000051195&lt;/groupId&gt;
          &lt;path&gt;
              &lt;id&gt;1000093190&lt;/id&gt;
              &lt;name&gt;Football&lt;/name&gt;
              &lt;englishName&gt;Football&lt;/englishName&gt;
          &lt;/path&gt;
          &lt;path&gt;
              &lt;id&gt;2000051195&lt;/id&gt;
              &lt;name&gt;Europa League&lt;/name&gt;
              &lt;englishName&gt;Europa League&lt;/englishName&gt;
          &lt;/path&gt;
      &lt;/events&gt;
       &lt;betoffers&gt;
          &lt;id&gt;2086105579&lt;/id&gt;
          &lt;eventId&gt;1004044027&lt;/eventId&gt;
          &lt;closed&gt;2018-05-16T18:45Z&lt;/closed&gt;
          &lt;live&gt;false&lt;/live&gt;
          &lt;startingPrice&gt;false&lt;/startingPrice&gt;
          &lt;criterion&gt;
              &lt;id&gt;1001221607&lt;/id&gt;
              &lt;label&gt;Winner&lt;/label&gt;
          &lt;/criterion&gt;
          &lt;betOfferType&gt;
              &lt;id&gt;4&lt;/id&gt;
              &lt;name&gt;Winner&lt;/name&gt;
          &lt;/betOfferType&gt;
          &lt;outcomes&gt;
              &lt;id&gt;2307553711&lt;/id&gt;
              &lt;odds&gt;15000&lt;/odds&gt;
              &lt;label&gt;AC Milan&lt;/label&gt;
              &lt;type&gt;OT_UNTYPED&lt;/type&gt;
              &lt;changedDate&gt;2018-02-05T22:19:04Z&lt;/changedDate&gt;
              &lt;oddsFractional&gt;14/1&lt;/oddsFractional&gt;
              &lt;oddsAmerican&gt;1400&lt;/oddsAmerican&gt;
          &lt;/outcomes&gt;
          &lt;outcomes&gt;
              &lt;id&gt;2307553715&lt;/id&gt;
              &lt;odds&gt;7000&lt;/odds&gt;
              &lt;label&gt;Arsenal&lt;/label&gt;
              &lt;type&gt;OT_UNTYPED&lt;/type&gt;
              &lt;changedDate&gt;2018-02-05T22:19:04Z&lt;/changedDate&gt;
              &lt;oddsFractional&gt;6/1&lt;/oddsFractional&gt;
              &lt;oddsAmerican&gt;600&lt;/oddsAmerican&gt;
          &lt;/outcomes&gt;
  </code></pre>
  
  <p>I am not getting any special error, when I add more items in the xml, only the php error I have written in. So Tried checking the network tab in the consol, but nothing there either. </p>