Insert Multiple Checkbox Value in Database Using PHP – Info PHP
Introduction
This article explains how to store multiple checkbox values in one column in a database in PHP.
Example
In this example, we implement storing multiple checkbox values in a database in PHP. There are certain steps we need to follow as explained below.
Step 1
Create a HTML form, test_post.php, with multiple checkboxes as shown below.
-
method=“post” enctype=“multipart/form-data”>“width:200px;border-radius:6px;margin:0px auto”>“1”>
“2”>Select Technolgy: PHP “checkbox” name=“techno[]” value=“PHP”> .Net “checkbox” name=“techno[]” value=“.Net”> Java “checkbox” name=“techno[]” value=“Java”> Javascript “checkbox” name=“techno[]” value=“javascript”> “2” align=“center”>“submit” value=“submit” name=“sub”> - if(isset($_POST[‘sub’]))
- {
- $host=“localhost”;
- $username=“root”;
- $word=“”;
- $db_name=“sub_db”;
- $tbl_name=“request_quote”;
- $con=mysqli_connect(“$host”, “$username”, “$word”,“$db_name”)or die(“cannot connect”);
- $checkbox1=$_POST[‘techno’];
- $chk=“”;
- foreach($checkbox1 as $chk1)
- {
- $chk .= $chk1.“,”;
- }
- $in_ch=mysqli_query($con,“insert into request_quote(technology) values (‘$chk’)”);
- if($in_ch==1)
- {
- echo‘‘;
- }
- else
- {
- echo‘‘;
- }
- }
- ?>
Step 2
Select multiple checkboxes as shown below.
Step 3
Now click on the submit button and a popup will be shown for confirmation as shown below.
Output
Article Prepared by Ollala Corp