Storing user inputs are important to be able to access those data later on. It might be to store data for easy searching or for report generation that will serve as basis in an organization’s decision-making process.
In my previous article, I introduced you with bootstraps new plugin which is the select2 that serves as a replacement for the basic combo box/dropdown box. With bootstrap’s select2 plugin, it would be easier to search and filter the results using a dropdown box/combo box.
So in this article, I am going to share with you on how to save those multiple selection using your bootstrap select2 plugin in the database using PHP and MySQLi. A foreach loop will help to achieve this. Prefer on the previous article entitled “MULTIPLE SELECT USING BOOTSTRAP” to have a detailed overview of the select2 plugin. Below is the screenshot of the select2 plugin.
PHP CODE TO SAVE VALUES FROM MULTIPLE SELECT
<?php
include('dist/includes/dbcon.php');
$res=$_POST['resident'];
foreach($res as $new)
{
mysqli_query($con,"INSERT INTO multiple(resident) VALUES('$new')")or die(mysqli_error($con));
}
echo "<script type='text/javascript'>alert('Successfully added new residents!');</script>";
echo "<script>document.location='index.php'</script>";
?>
OUTPUT FOR BOOTSTRAP SELECT2
Hope this works fine in you! Good day and watch for more upcoming articles! ^_^
DOWNLOAD SELECT2 FILE HERE
Database name: multiple_select
Username: admin
password: 123
database is located in dist/db
Username: admin
password: 123
database is located in dist/db
No comments:
Post a Comment