HTML/PHP How do I handle multiple checkboxes in each row of a table? I have 10 of them in each row. I made a for loop from $i=0 to 9 to have 10 of those in each row basically. I gave the values of those checkboxes ranging from 1 to 10. As for the name of the checkbox for each value, I wrote a name following by "[$i]" as suggested in some forums. But when I do echo $_POST[name[$i]] to get the values of those checkboxes that already have been checked, I get nothing. What am I doing wrong here?
Example would be, <input type="checkbox" name="animal" value="Cat" /> <input type="checkbox" name="animal" value="Dog" /> <input type="checkbox" name="animal" value="Bear" /> If you hit Submit, code should look similar to this. if(isset($_POST['submit']) { echo $_POST['animal']; } If I had your code, it be a lot easier to explain for your example. This is how I would have done when I first started, but you are missing the following code. <input type="checkbox" name="animal[]" value="Cat" /> <input type="checkbox" name="animal[]" value="Dog" /> <input type="checkbox" name="animal[]" value="Bear" /> Then hit sumbit with the following php code. if(isset($_POST['animal'])){ foreach($_POST['animal'] as $animal){ echo $animal; } } You have to set it up like arrays
Join our real-time social learning platform and learn together with your friends!