how to post multiple checkbox value in php?

Today, We want to share with you how to post multiple checkbox value in php?.In this post we will show you checkbox data from database, hear for how to get checked and unchecked checkbox array value in php we will give you demo and example for implement.In this post, we will learn about How to Get POST from multiple checkboxes? with an example.

Insert Multiple Checkbox Value in Database Using PHP

How to insert multiple checkbox value in a single column of MySQL using PHP Example

Read Also:  Show Multiple Checkbox Checked With Multiple Array Using Php

Here we using 2 file for insert multiple checkbox value:

  • index.php HTML form that that allows user to select option from the checkbox.
  • do_submit.php For process the user data.

index.php

<!DOCTYPE html>
<html>
<body>

<form method="post" action="do_submit.php">
<input type="checkbox" name="products[]" value="Mobile">I have a Mobile
<br>
<input type="checkbox" name="products[]" value="Laptop">I have a Laptop
<br>
<input type="checkbox" name="products[]" value="Computer">I have a Computer 
<br><br>
<input type="submit" value="Submit">
</form> 

</body>
</html>

do_submit.php

<?php
$url='127.0.0.1:8080';
$dbUser = "root";
$dbPasswrod = "9895dd";
$dbname = "admin";
$chociefill1 = $_POST['products'];
    $chk="";  
    foreach($chociefill1 as $chk1)  
       {  
          $chk.= $chk1.",";  
       }  

$link_new = mysqli_connect($url, $dbUser, $dbPasswrod, $dbname);
if (!$link_new) {
    die("sorry, Connection failed: " . mysqli_connect_error());
}
$query_s = "INSERT INTO chociefill(products)VALUES( '$chk' )";

if(mysqli_query($link_new,$query_s)) {

    echo 'Data added sucessfully';
} 
else {
    echo "Error: " . $query_s . "<br>" . mysqli_error($link_new);
}
mysqli_close($link_new);
?>

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.