title: php inserts only last array record into sql
body: <p>I have working code, which inserts data into csv file. Here is a part of it:</p>
  
  <pre><code>if (isset($_POST['array'])) {
          foreach ($_POST['array'] as $loop) {
              $txt = $txt . $loop['name'] . ";" . $loop['email'];
              $txt .="\n";
          }
      }
  </code></pre>
  
  <p>Instead of csv, i would like it to insert data into mysql database, so i have simply changed the code to:</p>
  
  <pre><code>    if (isset($_POST['array'])) {
          foreach ($_POST['array'] as $loop) {
  
              $sql = "insert into persons (Name, Email)
                      values ('" . $loop['name'] . "', '" . $loop['email'] . "')";     
          }
      }
  </code></pre>
  
  <p>Only the last record is saved into the persons table. There are no errors, but all the previous records except last are not inserted. Why?</p>