Save Multiple Checkbox values in Database using PHP is the our topic for this tutorial. Many times in our application we need to save the multiple or single checkbox value in the database for further processing like saving use hobbies, saving multiple answers of a question and many more. I have seen many people stuck and many times i got the mail regarding this matter. Finally i have created the video over the youtube and now i am also writing the tutorial for your help. If you have any questions than please comment below. If you want to see the example in live than you can visit my youtube video for saving the multiple checkbox in PHP.

Summary of how we will do this :-

  1. Create Database with 2 columns Values and Id.
  2. Create Html page with multiple checkboxes.
  3. PHP code for saving the checkbox values.
  4. Checkbox class for functions.
  5. List page for listing saved checkboxes.
  6. Update Page for updating the saved checkboxes.


Lets start with step by step just like the above points.

Create Database with 2 columns Values and Id.

You can use the above code for creating the checkbox table with 2 columns for saving the selected data.

Create Html page with multiple checkboxes.

by using the above code you will see some checkbox in the page. One important thing is we have added the [] to the name attribute of the input. [] helps us to create the array of the checkbox for using it in PHP.

PHP code for saving the checkbox values.

In this we have used a Class and after creating the object of the class we are using the functions of that class. In here we are using the addtoDatabase() function for saving the multiple checkbox values to database. This function will take the values and save it to the database.

Checkbox class for functions.

Checkbox class will be used for multiple functions which will handle the saving, listing and updating the checkbox values in the database. You can download the whole class from the bottom of the tutorial.

List page for listing saved checkboxes.

Listing page will be used for showing the saved values and providing the area to the user so that he can edit the particular values. For listing the values we are using the table.

For list we are using another function from the checkbox class.

As you can see we have added the checkbox values to the database and listing them over the page for showing the saved values to the user or for further modification.

Update Page for updating the saved checkboxes.


This is the last part of our tutorial. In this part we will just updated the previously saved values and before updating the new values we will see that we will get the values checked according to the saved ones. Like if we have 5 checkboxes and we have checked only 2 than at the time of updating we will get the 2 values already checked when we open the page. It will help us to find out the previous values.

For updating the values we will use updateCheckbox function.

Hope you like the tutorial and if you have any questions than please comment below. And please subscribe my youtube page.

Checkbox
Checkbox
checkbox.zip
3.2 KiB
48 Downloads
Details...