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 all of the checkboxes are checked. Why is this?
Here is the testchk.html
<html>
<head>
<title>testchk</title>
</head>
<body bgcolor="pink">
<h3> choice item</h3>
<form action="testchk.php" method="post">
<input type="checkbox" name="chk1[]" value="vegetables">vegetables
<input type="text" name="temperature[]"><br />
<input type="checkbox" name="chk1[]" value="frozen">frozen products
<input type="text" name="temperature[]"><br />
<input type="checkbox" name="chk1[]" value="dried">dried goods
<input type="text" name="temperature[]"><br />
<input type="checkbox" name="chk1[]" value="cooling">
<input type="text" name="temperature[]"><br />
<br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
and here is the testchk.php
include ("db.php");
$checkbox1 = $_POST['chk1'];
$temperature = $_POST['temperature'];
if ($_POST["submit"]=="submit") {
for ($i=0; $i<sizeof($checkbox1); $i++) {
$sql="INSERT INTO test (Name, temp) VALUES ('".$checkbox1[$i]."', '".$temperature[$i]."' )";
mysql_query($sql) or die(mysql_error());
}
echo "insert";
}