web 2.0

How to use PHP & Multiple Checkbox

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

PHP Multiple Checkbox

PHP Multiple Checkbox
.
.
.

Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.