title: PHP Select List - Insert multiple values in database
body: <p>I'm trying to insert multiple values in the database using select list. What I got so far:</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;form enctype="multipart/form-data" action="" method="post"&gt;
              &lt;select name="cars[]" multiple="multiple" style="width:300px"&gt;
              &lt;?php 
              $getcars = mysql_query("SELECT cars_id, cars_name FROM car");
              while ($row = mysql_fetch_assoc($getcars)) {
                  $car_id = $row['cars_id'];
                  $car_name = $row['cars_name'];
              ?&gt;
              &lt;option value="&lt;?php echo $car_id ?&gt;"&gt;&lt;?php echo $car_name ?&gt;&lt;/option&gt;
              &lt;?php } ?&gt;
              &lt;/select&gt;&lt;br /&gt;
              &lt;input type="submit" name="submit" value="Submit"/&gt;&lt;br/&gt;
          &lt;/form&gt; 
  </code></pre>
  
  <p>PHP</p>
  
  <pre><code>        $cars= $_POST['cars'];
          echo $cars;
          for($i = 0; $i &lt; count($cars); $i++){
              echo $cars[$i];
              $carGroups = mysql_query("INSERT INTO car_groups VALUES('$company','$cars[$i]]')"); 
          }
  </code></pre>
  
  <p>Unfortunately it doesn't work, I tried to print $cars to check the resulted value. It prints "Array", and when I tried to print $cars[$i] it prints nothing.</p>
  
  <p>Does anyone know what the problem is?</p>