Today, We want to share with you how to show multiple checkbox checked in php.In this post we will show you how to retrieve multiple checkbox value from database in php using explode, hear for creating multiple checkbox with submit button and transfer the checkbox checked values on same page we will give you demo and example for implement.In this post, we will learn about PHP Multiple Checkbox Array Handling Tutorial with an example.
How to Get/Display Multiple checkbox selected values in php on same page?
here user select its all the selection and click on submit button get using PHP $_POST Varibles.
index.php
<!doctype html> <html> <head> <meta charset="utf-8"> <title>How to Get/Display Multiple checkbox selected values on same page using PHP</title> </head> <body> <h2>Pass checkbox checked values on same page.</h2> <form method="post" action=""> <input type="checkbox" name="product[]" value="Mobile"><label>Mobile</label><br/> <input type="checkbox" name="product[]" value="Mobile Smart"><label>Mobile Smart</label><br/> <input type="checkbox" name="product[]" value="Lenova Laptop"><label>Lenova Laptop</label><br/> <input type="checkbox" name="product[]" value="Computer"><label>Computer</label><br/> <input type="checkbox" name="product[]" value="LCS New"><label>LCD New</label><br/><br/> <input type="submit" name="submit" Value="submit"> </form> </br> <?php if (isset($_POST['submit'])) { $productbox = $_POST['product']; $i = 0; While($i < sizeof($productbox)) { echo "CheckBox checked Values = " . $productbox[$i] . '</br>'; $i++; } } ?> </body> </html>
Show Multiple Checkbox Checked With Multiple Array Using Php
index.php
<?php // select product value $select_products = array ( array("name"=>"Mobile","value"=>1), array("name"=>"Laptop","value"=>2) ); // product detail $products_detail = array ( array("name"=>"Mobile","value"=>1), array("name"=>"Laptop","value"=>2), array("name"=>"LCD","value"=>3), array("name"=>"Computer CNG","value"=>4) ); $pdetailsall=""; foreach ($select_products as $key => $val) { $pdetailsall .= ',' .$val['value']; } $pdetailsall = substr($pdetailsall,1); $pdetailsall = explode(',',$pdetailsall); foreach ($products_detail as $ld) { if(in_array($ld['value'],$pdetailsall)) { ?> <div class="form-group" style="margin-bottom: 0px;"> <input type="checkbox" name="products[]" checked value="<?php echo $ld['value']; ?>"> <label><?php echo $ld['name']; ?></label> </div> <?php } else { ?> <div class="form-group" style="margin-bottom: 0px;"> <input type="checkbox" name="products[]" value="<?php echo $ld['value']; ?>"> <label><?php echo $ld['name']; ?></label> </div> <?php } } ?>
I hope you get an idea about how to display checked checkbox value in php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.
I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.