paulus4605 Posted August 17, 2011 Share Posted August 17, 2011 I have created this multiple form de hond is behandeld tegen:<?php mysql_connect("127.0.0.1", "root", "pass")or die("cannot connect"); mysql_select_db("tobysplace")or die("cannot select DB"); $query="SELECT * FROM vaccination"; /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */ $result = mysql_query ($query); echo "<select multiple name=vaccination[] value=''><option>de hond is behandeld tegen:</option>"; // printing the list box select command while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option value=".$nt['vaccination_id'].">".$nt['vaccination_name']."</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box ?> everything is stored in a session with $_SESSION['vaccination'] = $_POST['vaccination']; how do I get each unique id from each selected item inserted in the table dog_vaccination where 2 foreignkeys are held which is dog_id and vaccination_id as foreignkeys. thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/244979-multiple-selected-items-from-dropdownlist-inserting-in-table/ Share on other sites More sharing options...
joel24 Posted August 17, 2011 Share Posted August 17, 2011 is something like this what you're after? you need to enclose the select name in quotes; echo "<select multiple name='vaccination[]' value=''><option>de hond is behandeld tegen:</option>"; and then when you process the form (this assumes the dog's id is stored in the session under the session variable dog_id if (is_array($_POST['vaccination'])) { foreach ($_POST['vaccination'] AS $vaccination) { $dog = $_SESSION['dog_id']; @mysql_query("INSERT INTO vaccination SET vaccination_id='$vaccination', dog_id='$dog'"); } Quote Link to comment https://forums.phpfreaks.com/topic/244979-multiple-selected-items-from-dropdownlist-inserting-in-table/#findComment-1258440 Share on other sites More sharing options...
paulus4605 Posted August 17, 2011 Author Share Posted August 17, 2011 thanks you are a life saver Quote Link to comment https://forums.phpfreaks.com/topic/244979-multiple-selected-items-from-dropdownlist-inserting-in-table/#findComment-1258443 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.