I have a form that uses a checkbox and it gets all the data from the mysql database. So there could be from 1 to unlimited of the checkboxes.
I need to get each of those that are checked when the form is submitted.
It works if all of them are checked, but if only a few are checked, it will either show none or just one of them.
Here is the code I am using to show the checkboxes with data:
while ($myrow = mysqli_fetch_array($result)){
echo<<<END
<input type="checkbox" id="units" name="unit[$i]" value="$myrow[unit_id]" /> $myrow[unit_id]<br />
END;
$i++;
}//end while
Here is the code I am using when the form is submitted:
$i=0;
while($_POST["unit"][$i] != ""){
$unit = $_POST["unit"][$i];
$unit = $res2->real_escape_string($unit);
echo $unit."<br />";
$i++;
} // end while
I believe the problem is the fact that I have while($_POST["unit"[$1] != "")
and if one box is checked and then another one 2 or 3 down is checked, it sees the 2nd one empty and stops.
If that's the case, I need help to figure out how to make it run through them all and print out the ones that were checked. Remember, there could be anywhere from 1 to unlimited checked so it can't be a set number like while($i <= 50)
Thank you!