I'm trying to get a input from a multiselect into a database. below is a snippet of the select field in the form I have. I did find the suggestion to [] so I added that. was a big step forward
<select name="project_dicipline[]" data-placeholder="Select uw dicipline(s)" class="chosen-select" multiple style="width:350px;">
<option value=""></option>
<option value="Elektra_LS">Elektra LS</option>
<option value="Elektra_MS">Elektra MS</option>
<option value="Elektra_OV">Elektra OV</option>
</select>
Below is what I got for reading the info out of the _POST it works fine if I just echo the foreach() line (got it from another post on stackoverflow), but I want to add it in a database, and I'm not sure how to get that done. I could really use some help for that.
$project_dicipline = array();
foreach ($_POST['project_dicipline'] as $project_dicipline)
$project_dicipline = mysqli_real_escape_string($conn, $project_dicipline);
echo $project_dicipline;
--edit-- below is the connection to db. That part i know works, because the rest of the form gets validated and added to the form. for that reason i have cut out a lot of the fields out of the query. (all variables have been escaped before the query is run)
$conn = mysqli_connect($servername, $usernamedb, $passwordDB, $database);
if (!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}
$query = "INSERT INTO projects (project_status, project_name, project_client, project_diciplines)
VALUES('New', '$project_naam', '$project_plaats', '$project_client_company', '$project_dicipline')";
mysqli_query($conn, $query);