dude753 Posted September 25, 2006 Share Posted September 25, 2006 HowdyI have a drop down menu which has multiple selection enabled. I want to put all the options selected into a db seperated by a commar.So:Orange|RedEtc.Here is my code:[code]<td width='30%' valign='top'><strong>Access</strong><br><i>To select more than one category hold ctrl then click.</i></td> <td valign='top'><select name='access' multiple='multiple' height='$height'>"; while($r=mysql_fetch_array($result)) { // start looping $name = $r["name"]; $id=$r["id"]; echo "<option value='$name'>$name</option>"; // echoing out different categories } echo "<option value='Admin'>Admin</option></select> </td>[/code]Then, to insert it into the db I have:[code]else if($_POST['Submit'] == "Update") //if submit is hit{ mysql_connect("$localhost","$dbuser","$dbpass") or die("error"); mysql_select_db("$dbname") or die(mysql_error()); //makes incoming data variables $username = $_POST['username']; $password = $_POST['password']; $access = $_POST['access']; $id = $_POST['id']; if($username && $password && $access) { $password = md5($_POST['password']); $result = mysql_query("UPDATE users SET username='$username', password='$password', access='" . join(",",$_POST["access"]) . "' WHERE id='$id'") or die (mysql_error()); }[/code]For some reason this isn't working at all. It only allows me to select one option on the drop down. Any idea why this is?I'm usnig Firefox.Thanks! Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 25, 2006 Share Posted September 25, 2006 This will point the way ... save it and test it to see what it does:[code]<?phpif (isset($_POST['submit'])) { $test = $_POST['skill_sets']; print_r($test);}?><html><head><title>Test</title></head><body><form name="test" method="post"><select name="skill_sets[]" multiple size="3"><option value="Academics">Academics</option><option value="Math">Math</option><option value="Problems">Problem Solving</option><option value="Project Management">Project Management</option><option value="Basketweaving">Basketweaving</option></select><input type="submit" name="submit" value="Pick Some"/></form></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
thepip3r Posted September 25, 2006 Share Posted September 25, 2006 yes... AndyB's method will write all of the selected drop down options into another dimension of the $_POST global so then you can just loop through that $_POST['skill_sets'] array to write all of the selected values do your DB... Quote Link to comment 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.