Insert Value From CheckBox In Database (MySQL) In PHP – Info PHP
In the last article you saw how to insert a value from a radio button in the MySQL database in PHP. Now in this article you will see how to insert a value from a checkbox in the MySQL database. Using a checkbox you can insert multiple values in the MySQL database in PHP.
First of all we will create a database and a table in MySQL.
Create config.php file
Now we will create a config.php file for connecting the database to all PHP files.
Create the form.php file
Now we will create a form.php file by which we will insert a value through checkboxes in the MySQL database.
Create checkbox.php file
No we will create a PHP file in which we include a config.php file and write the insert command for inserting the data in the database.
For running the above code we will write in the web browser “http://localhost/foldername/form.php” .
Now we select any checkbox. Suppose we select four checkboxes i.e. Vineet Saini, Ravi Sharma, Rahul Dube, Priyanka Sachan. Then we will click on the submit button.
When we click on the submit button then you will get a message i.e. Record is inserted.
Now you will see there are four records inserted in the database. Like as in the following image.
So in this article you saw how to insert multiple records in a MySQL database through a checkbox. Using this article one can easily understand insertion of multiple data in a MySQL database.
Some Helpful Resources
Article Prepared by Ollala Corp