Jump to content


Photo

Drop down menus with multiple selection


  • Please log in to reply
2 replies to this topic

#1 dude753

dude753
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 25 September 2006 - 07:20 PM

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:
<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>

Then, to insert it into the db I have:
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.

Thanks!

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 25 September 2006 - 11:37 PM

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

<?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>

Legend has it that reading the manual never killed anyone.
My site

#3 thepip3r

thepip3r
  • Members
  • PipPipPip
  • Advanced Member
  • 289 posts

Posted 25 September 2006 - 11:39 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users