title: How to insert multiple rows by select or checkbox
body: <p>I've got a problem with inserting multiple row to one table.</p>
  
  <p>I've got a 3 tables:
  1. student with id_student
  2. ankieta with id_ankieta
  3. student_ankieta with id_student and id_ankieta</p>
  
  <p>I want to choose students from database using select or checkbox and choose one id_ankieta. After confirming, there are rows created in table (student_ankieta).
  Now I can choose students but when I confirm, only one student gets added to the database.</p>
  
  <p>Can anyone help me corect the code?</p>
  
  <pre><code>     &lt;?php
  echo'&lt;form method="post" action="student_ankieta.php"&gt;
          &lt;div class="box" style="margin:0 auto; top:0px;"&gt;
              &lt;h1&gt;Student - ankieta:&lt;/h1&gt;
  
              &lt;label&gt;
                  &lt;span&gt;&lt;br/&gt;Ankieta:&lt;/span&gt;
              &lt;/label&gt;
              &lt;select class="wpis" name="id_ankieta"&gt;
                  &lt;option&gt;wybierz ankiete&lt;/option&gt;';
                  $query = "SELECT * FROM ankieta";
                  $result = mysql_query($query);
                  while ($row = mysql_fetch_array($result)) 
                      {
                         echo '&lt;option value="'.$row['id_ankieta'].'"&gt;' . $row{'rok_akademicki'}.' '. $row{'semestr_akademicki'}.' '.$row{'active_ankieta'} .'&lt;/option&gt;';
                      }
              echo '
              &lt;/select&gt;';
  
              $query = "SELECT * FROM student";
              $result = mysql_query($query);
              echo'
              &lt;label&gt;
                  &lt;span&gt;&lt;br/&gt;Wybierz stundentów:&lt;/span&gt;
              &lt;/label&gt;
              &lt;select multiple="multiple" name="id_student[]" size="10"&gt;';
              while ($row = mysql_fetch_assoc($result)) 
                  {
                      echo '&lt;option  class="wpis" value="'.$row['id_student'].'" /&gt;'.$row{'pesel'}.' '. $row{'nazwisko'}.' '.$row{'imie'} .'&lt;/option&gt;';
                  }
  
              echo'&lt;br/&gt;&lt;input class="button" type="submit" value="Dodaj ankiete" name="dodaja"&gt;';             
  
              if(isset($_POST['dodaja'])) 
                  {
                      $id_ankieta = $_POST['id_ankieta'];
                      if(empty($_POST['id_ankieta']))  
                          {
                              echo '&lt;p style="margin-top:10px; font-size:75%; font-family: Calibri; color: red; text-align:center;"&gt;Musisz wypełnić wszystkie pola.&lt;/p&gt;';
                          } 
                          else
                              {
                                 $id_student = $_POST['id_student'];
                                 for ($i = 0; $i &lt; count($id_student); $i++) 
                                 {
                                      $id_student = $id_student[$i];
                                      mysql_query("INSERT INTO student_ankieta (id_student, id_ankieta) VALUES ('" . $id_student . "','$id_ankieta')");
                                  }
                              }
                  }
    echo'&lt;/div&gt;&lt;/form&gt;';?&gt;
  </code></pre>