title: From Textarea to multiple value insert using PDO
body: <p>I am struggling with my PDO insert into a database from a textarea which contains information like this:</p>
  
  <p>user1|pass1
  user2|pass2
  user3|pass3</p>
  
  <p>The current problem is that the LAST account of this list gets inserted into my DB multiple times, but I can't figure it why this is happening. This is my Code:</p>
  
  <pre><code>// Divide the textarea by line into a string array
  $accounts = explode(PHP_EOL, $_POST['accountData']);
  
  // Prepare the Query
  $query = "INSERT INTO accounts (username, password, referral, dateCreated,region,idOrder) VALUES ";
  // Create the multiple value placeholder
  $qPart = array_fill(0, sizeof($accounts), "(?, ?, ?, ?, ?, ?)");
  $query .= implode(",",$qPart);
  $stmt = $dbh-&gt;prepare($query);
  $idOrder=100;
  
  switch($priority)
  {
      case("low"):
          $date="2050-01-01 00:00:00.000";
          $i = 1;
          foreach($accounts as $item){
              list($user, $pass) = explode("|", $item);
              echo $user . ":" . $pass . "&lt;br&gt;";
              $stmt-&gt;bindParam($i++, $user);
              $stmt-&gt;bindParam($i++, $pass);
              $stmt-&gt;bindParam($i++, $refid);
              $stmt-&gt;bindParam($i++, $date);
              $stmt-&gt;bindParam($i++, $region);
              $stmt-&gt;bindParam($i++, $idOrder);
          }
      break;
  
      case("high"):
          $date="2000-01-01 00:00:00.000";
          foreach($accounts as $item){
              list($user, $pass) = explode("|", $item);
              echo $user . ":" . $pass . "&lt;br&gt;";
              $stmt-&gt;bindParam($i++, $user);
              $stmt-&gt;bindParam($i++, $pass);
              $stmt-&gt;bindParam($i++, $refid);
              $stmt-&gt;bindParam($i++, $date);
              $stmt-&gt;bindParam($i++, $region);
              $stmt-&gt;bindParam($i++, $idOrder);
          }
      break;
  }
  $stmt-&gt;execute();
  </code></pre>
  
  <p>I echod $user and $pass and it showed the right user:pass (= 3 different users and passwords). But in the DB only the LAST user got inserted multiple times. Can you help me ?</p>