iam having trouble submitting data from the checkboxes to the database. If I check the second and and third or any other value(s), it submits a zero. It seems to be considering the first option even if it isnt checked. The items in the checkbox are returned from a MSQL database. Here is my code for that
<fieldset><legend>Procedures</legend>
<?php $a=mysql_query("SELECT * FROM tests");$x=1;
?><table> <?php $x=0;
while($p=mysql_fetch_array($a)){?>
<tr><td>
<input type="checkbox" name="test[]" value="<?php echo
$p['idtests'];?>"/></td><td> <?php echo $p['test'];?></td>
<td> <input type="text" size=3 name="qty[]"/>
</td></tr>
<?php echo '<br/>' ; $x++; }?> </table>
</fieldset>
And here is the code to insert :
<?php $f=$_POST['test']; $qty=$_POST['qty'];
for($i=0;$i<COUNT($f);$i++)
{
$price=mysql_fetch_array(mysql_query("SELECT * FROM tests WHERE idtests='".$f[$i]."'"));
$sql4=mysql_query("INSERT INTO treatdetails VALUES('','".$qty[$i]."','".$price['cost']."','$id','".$f[$i]."')");
} ?>
It inserts zeroes whenever the first checkbox is not checked. Any help will be highly appreciated
Aucun commentaire:
Enregistrer un commentaire