How to use PHP & Multiple Checkbox This tutorial how to using PHP read a variable from multiple checkbox
ShotDev Focus:
- Using PHP & multiple checkbox
Example
php_multiple_checkbox1.php
<html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form action="php_multiple_checkbox2.php" method="post" name="form1"> Please select color.<br> <input type="checkbox" name="chkColor[]" value="Red">Red<br> <input type="checkbox" name="chkColor[]" value="Blue">Blue<br> <input type="checkbox" name="chkColor[]" value="Green">Green<br> <input type="checkbox" name="chkColor[]" value="Orange">Orange<br> <input type="checkbox" name="chkColor[]" value="Black">Black<br> <input name="btnSubmit" type="submit" value="Submit"> </form> </body> </html>
php_multiple_checkbox2.php
<html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <? for($i=0;$i<count($_POST["chkColor"]);$i++) { if(trim($_POST["chkColor"][$i]) != "") { echo "chkColor $i = ".$_POST["chkColor"][$i]."<br>"; } } ?> </body> </html>
Create a php file and save to path root-path/myphp/
Run
http://localhost/myphp/php_multiple_checkbox1.php
Screenshot