title: PHP read XML and write in Database
body: <p>i have a XML file and need the data in a database after i checked them. so i display the data in a table and after that i try to write the data in a database. but with my code i get only the first set of data from the xml in my database. but there are at least 20  or more in each xml. How can i write all data in the database?</p>
  
  <p>with this code i display the data from the xml</p>
  
  <pre><code>&lt;form action="insert.php" method="post" /&gt;
      &lt;table id="Wagen"&gt;
          &lt;thead&gt;
            &lt;tr&gt;        
              &lt;th&gt;Typ&lt;/th&gt;
              &lt;th&gt;Kennzeichen&lt;/th&gt;
              &lt;th&gt;Fahrer&lt;/th&gt;
            &lt;/tr&gt;
          &lt;/thead&gt;
  
          &lt;tbody&gt;
  
      &lt;?php
        $url = ('./cars.xml');
        $xml = simplexml_load_file( urlencode($url), null, true);
  
  
         foreach ( $xml-&gt;car as $cars ) :?&gt;
      &lt;tr&gt;        
              &lt;td&gt;&lt;input type="hidden" name="name" value="&lt;?php echo $cars-&gt;typ; ?&gt;"&gt;&lt;?php echo $cars-&gt;typ; ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input type="hidden" name="kfz-nr" value="&lt;?php echo $cars-&gt;plate; ?&gt;"&gt;&lt;?php echo $cars-&gt;plate; ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input type="hidden" name="fahrer" value="&lt;?php echo $cars-&gt;driver; ?&gt;"&gt;&lt;?php echo $cars-&gt;driver; ?&gt;&lt;/td&gt;
      &lt;/tr&gt;
  
  &lt;?php endforeach; ?&gt;
  
         &lt;/tbody&gt;
      &lt;/table&gt; 
      &lt;input type="submit" name="senden" value="XML speichern" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and with this code i try to write the data in the database. but i get only the first row from my table. not the others.</p>
  
  <pre><code>&lt;?php
  
       error_reporting(E_ALL); 
          $MYSQL_HOST = 'localhost'; 
          $MYSQL_USER = 'username'; 
          $MYSQL_PASS = 'password'; 
          $MYSQL_DATA = 'database'; 
  
          $connid = @mysql_connect($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASS) OR die("Error: ".mysql_error());
          mysql_select_db($MYSQL_DATA) OR die("Error: ".mysql_error()); 
  
         if (isset($_POST['senden']))
      {
        $sql = 
                "INSERT INTO myTable 
                (fahrzeug,
                 kennzeichen,
                 fahrer
                )
                VALUES
                ('".mysql_real_escape_string(trim($_POST['name']))."',
                 '".mysql_real_escape_string(trim($_POST['kfz-nr']))."',   
                 '".mysql_real_escape_string(trim($_POST['fahrer']))."'); 
                  mysql_query($sql) OR die("&lt;pre&gt;\n".$sql."&lt;/pre&gt;\n".mysql_error()); 
                  mysql_query("SET NAMES 'utf8'");
      }
  ?&gt;
  </code></pre>
  
  <p>i hope some one can help me. :)</p>