Jump to content

Drop down menus with multiple selection


dude753

Recommended Posts

Howdy

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.

So:
Orange|Red

Etc.

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!
Link to comment
Share on other sites

This will point the way ... save it and test it to see what it does:

[code]<?php
if (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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.