How to use PHP & Checkbox This tutorial how to using PHP read a variable from checkbox
ShotDev Focus:
- Using PHP & Checkbox
Example
php_checkbox1.php
<html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form action="php_checkbox2.php" method="post" name="form1"> Please select color.<br> <input type="checkbox" name="chkColor1" value="Red">Red<br> <input type="checkbox" name="chkColor2" value="Blue">Blue<br> <input type="checkbox" name="chkColor3" value="Green">Green<br> <input name="btnSubmit" type="submit" value="Submit"> </form> </body> </html>
php_checkbox2.php
<html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <? echo $_POST["chkColor1"]."<br>"; echo $_POST["chkColor2"]."<br>"; echo $_POST["chkColor3"]."<br>"; ?> </body> </html>
Create a php file and save to path root-path/myphp/
Run
http://localhost/myphp/php_checkbox1.php
Screenshot