title: checkbox value to mysql/php
body: <p>im triyng to figure out a problem for days and have some progress but im stuck with some checkbox page.</p>
  
  <p>So the "project" is some kind of "online car stand" and im stuck in the insert car part.</p>
  
  <p>I got the html and php for insert a car into the sql table.</p>
  
  <p>Then after the car i have a link to insert extras of the car, like abs,cruise control, gps ...etc...</p>
  
  <p>The Html is something like this:</p>
  
  <pre><code>&lt;?php
  include "verifica.php";
  ?&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;link rel="stylesheet" href="styles.css"&gt;
  &lt;title&gt; Stand Automovel
  &lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;form action="extras.php" method="POST"&gt;
  &lt;P class="style2"style2"&gt;&amp;nbsp;Extras:
  
  &lt;div class="style2"&gt;
  
  
    &lt;input type="checkbox" name="chk" value="1"&gt;GPS&lt;br&gt;
    &lt;input type="checkbox" name="chk" value="2"&gt;ABS&lt;br&gt;
    &lt;input type="checkbox" name="chk" value="3"&gt;Computador De Bordo&lt;br&gt;
    &lt;input type="checkbox" name="chk" value="4"&gt;Ar Condicionado&lt;br&gt;
  
  
  &lt;/div&gt;
  
  
  &lt;P&gt;&amp;nbsp;&lt;/P&gt;
      &lt;P&gt;&lt;INPUT TYPE=submit VALUE="Submeter"&gt; &lt;INPUT TYPE=reset     VALUE="Limpar"&gt; &lt;/P&gt;
      &lt;P&gt;&amp;nbsp;&lt;/P&gt;
  
  &lt;/form&gt;
  
  
  &lt;/body&gt;
  </code></pre>
  
  <p>The php page code is this one:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="UTF-8"&gt;
          &lt;title&gt;Inserir Automoveis&lt;/title&gt;
      &lt;/head&gt;
  &lt;body&gt;
  
  &lt;?php
    include "connect.php";
  $sql = "INSERT INTO extra (extra.id_carro,extra.id_lista_extra) SELECT carro.id_extras , ? FROM carro,lista_extra,extra ORDER BY carro.id_carro DESC LIMIT 1";
  
  if($teste= $mysqli-&gt;prepare($sql)) {
  
  
      $teste-&gt;bind_param("s",$_REQUEST["extra.id_lista_extra"]);
  
      $teste-&gt;execute();
  
  
  if ($teste&gt;affected_rows == -1) {
   echo $print;
    echo "&lt;p&gt;". $mysqli-&gt;error. "&lt;/p&gt;";
  
  
  }
  else {
    echo "&lt;sp&gt;Carro inserido com sucesso!&lt;/p&gt;";
  }
  
  
  }
  
  
  
  ?&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>The goal with that $sql is to get the last id from last car inserted on row cars and add 1 extra to him passed by the check box.</p>
  
  <p>i have tried just with 1 box because i read that if a checkbox was unchecked pass "null"argument.</p>
  
  <p>I tried already with diferent aproaches. My final goal is create a for cicle that creates the number of rows in table extra for each number of extra checked in my checkbox.</p>
  
  <p>(i tried something like this but with no sucess)</p>
  
  <pre><code>$checkbox1 = $_POST['chk'];
  if($_POST["Submit"]=="Submit"){
  
      for ($i=0;$i&lt;sizeof ($checkbox1)$i++){
      $sql = "INSERT INTO extra (id_lista_extra)     values('".$checkbox1[$i]."')";   
      mysql_query($sql) or die(mysql_error());
     }
  }
  </code></pre>
  
  <p>i got some php errors on that $i .</p>
  
  <p>If someone can give me a hint i would appreciate.</p>
  
  <p>Thanks</p>