Jump to content


This topic is now archived and is closed to further replies.


Drop down menus with multiple selection

Recommended Posts


I 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.



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"];
  echo "<option value='$name'>$name</option>"; // echoing out different categories
    echo "<option value='Admin'>Admin</option></select>

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());

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.


Share this post

Link to post
Share on other sites
This will point the way ... save it and test it to see what it does:

if (isset($_POST['submit'])) {
    $test = $_POST['skill_sets'];


<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>
<input type="submit" name="submit" value="Pick Some"/>

Share this post

Link to post
Share on other sites
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...

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.