title: Insert Multiple Rows in Mysql Using Foreach array
body: <p>I am trying to get multiple rows to insert into a mysql table from a form that allows for multiple checkboxes.</p>
  
  <p>This is the form:</p>
  
  <pre><code>&lt;input type='submit' name='invite-group' value='Invite To Group'&gt;
  &lt;br /&gt;
  &lt;?php
  $query2aac = mysql_query("SELECT * FROM follow WHERE yoozer1='$userdb1a' AND  followaccept='Yes' ORDER BY yoozer2 DESC");
  
  while($row2aac = mysql_fetch_array($query2aac))
  {
      $rowid = $row2aac['followid'];
      $yoozer2aac = $row2aac['yoozer2'];
      $yoozer2aacurl = strtolower($yoozer2aac);
      $palurl = '&lt;a href="http://www.bunchofus.com/fanpage/' . $yoozer2aacurl . '"&gt;' .    $yoozer2aac . '&lt;/a&gt;';
      echo '&lt;input type= "hidden" name = "id[]" value="' . $rowid . '"&gt;&lt;/input&gt;';
      echo '&lt;input type= "checkbox" name = "friends[]" value="' . $yoozer2aac . '"&gt;' . $palurl . '&lt;/input&gt;&lt;br /&gt;';
  }   
  ?&gt;
  </code></pre>
  
  <p>This is the php:
      
  
  <pre><code>if ($submit)
  {
      $submit = $_POST['invite-group'];
      $date1 = date("Y-m-d");
      $lowername = strtolower($username);
      $combined = $_POST['friends'];
  
      foreach ($combined as $username) 
      {
          $insert1 = mysql_query("INSERT INTO grprequest VALUES ('','$grpid3','$username','$myuser','$grprights3','$grpactive3')");
      }
  }
  ?&gt;
  </code></pre>
  
  <p>It is inserting one line into the database but not multiple lines. If I echo the username after the foreach, multiple usernames are showing.</p>
  
  <p>If anyone could help I would appreciate it.</p>