Infolinks

Breaking

Adsense

Thursday, April 28, 2016

SAVING VALUES FROM MULTIPLE SELECT USING PHP AND MYSQLI

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


First thing to do is connect to your database by including the dbcon.php. Next thing is to retrieve the data from the select2 box using the $_POST. A foreach loop is then used to get each value and store it individually in the $new variable and insert it in the multiple table.

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

SAVING VALUES FROM MULTIPLE SELECT USING PHP AND MYSQLI

No comments:

Post a Comment

Adbox