title: How can I insert only values in text boxes where corresponding check boxes are checked?
body: <p>In my program, I have 4 checkboxes that correspond to 4 text fields. The PHP script should insert values into my database only where the checkboxes are checked. Unfortunately, it only works properly if <em>all</em> of the checkboxes are checked. Why is this?</p>
  
  <p>Here is the testchk.html</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;testchk&lt;/title&gt;
  &lt;/head&gt;
  &lt;body bgcolor="pink"&gt;
  &lt;h3&gt; choice item&lt;/h3&gt;
  &lt;form action="testchk.php" method="post"&gt;
      &lt;input type="checkbox" name="chk1[]" value="vegetables"&gt;vegetables
      &lt;input type="text" name="temperature[]"&gt;&lt;br /&gt;
      &lt;input type="checkbox" name="chk1[]" value="frozen"&gt;frozen products
      &lt;input type="text" name="temperature[]"&gt;&lt;br /&gt;
      &lt;input type="checkbox" name="chk1[]" value="dried"&gt;dried goods
      &lt;input type="text" name="temperature[]"&gt;&lt;br /&gt;
      &lt;input type="checkbox" name="chk1[]" value="cooling"&gt;
      &lt;input type="text" name="temperature[]"&gt;&lt;br /&gt;
      &lt;br&gt;
      &lt;input type="submit" name="submit" value="submit"&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and here is the testchk.php</p>
  
  <pre><code>include ("db.php");
  
  $checkbox1 = $_POST['chk1'];
  $temperature = $_POST['temperature'];
  if ($_POST["submit"]=="submit") {
      for ($i=0; $i&lt;sizeof($checkbox1); $i++) {
          $sql="INSERT INTO test (Name, temp) VALUES ('".$checkbox1[$i]."', '".$temperature[$i]."' )";  
          mysql_query($sql) or die(mysql_error());
  
      }
      echo "insert";
  }
  </code></pre>