Académique Documents
Professionnel Documents
Culture Documents
(MySQL) In PHP
Apr 15 2012
Article
2
8
533k
lin kedIn
google Plus
o
o
o
o
Expand
Easily Add PDF Word & Excel Function to Your .NET Apps
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.
Create Database
Create Table
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.
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.
Output
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.
Conclusion
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.
You should specify
Didn't tested it, but you can try like this. Don't
forget to replace mysql with mysqli.
<html>
<body>
<form method="post" action="chk123.php">
Flights on: <br/>
<input type="checkbox" name="Days[]"
value="Daily">Daily<br>
<input type="checkbox" name="Days[]"
value="Sunday">Sunday<br>
<input type="checkbox" name="Days[]"
value="Monday">Monday<br>
<input type="checkbox" name="Days[]"
value="Tuesday">Tuesday <br>
<input type="checkbox" name="Days[]"
value="Wednesday">Wednesday<br>
<input type="checkbox" name="Days[]"
value="Thursday">Thursday <br>
<input type="checkbox" name="Days[]"
value="Friday">Friday<br>
<input type="checkbox" name="Days[]"
value="Saturday">Saturday <br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$query="INSERT INTO example (orange) VALUES
('" . $checkBox . "')";
echo "Complete";
?>
shareimprove this answer edited Nov 24 '13 at 16:57 answered Nov 24 '13 at 16:07
Viacheslav Kondratiuk
3,33162962
Do you mind kindly showing me this in code? – SirBT Nov 24 '13 at 16:3