im trying to create multiple checkboxes in html using a while loop in php.
while($counter != 5){
?>
<Input type = 'Checkbox' Name = '<?php echo '$foods[$counter]'; ?>' value ="yeeeey">
<?php
echo $foods[$counter];
echo " ";
?>
<input type="text" class="textfield" value="" name="<?php echo $foods_val[$counter]; ?>"
onkeypress="return isNumber(event)" style="width:55px";>
<P>
<?php
$counter++;
}
$counter = 0;
?>
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Input order">
</FORM>
just dont mind the text field for now. basically, im trying to create multiple checkboxes with their name and value based on an array.
$foods = array($rw, $mrd, $rd, ... , $bb);
and each of those variables contains a string. i have a code to detect which checkboxes were checked
if(isset($_POST['Submit1'])){
while($counter != 21){
if(isset($_POST['$foods[$counter]'])){
echo "yeeeeeeeeeeeeeeeeeeeeey";
}
$counter++;
}
}
however, when i try checking some boxes, the string "yeeeeeeeeeeeeeeeeeeeeey" is never printed. it seems that $_POST['$foods[$counter]'] is empty even when it is supposed to contain "yeeeeeey". how do you solve this? sorry for crappy formatting, still getting used to it. thanks
small update. all variables inside $foods[$counter] now contains the same string: "food". my problem now is that all checkboxes behaves as if they were checked and contains the same value "yeeey"