tags:

views:

747

answers:

1

Couldn't find any good information on how to do this so I thought I'd add it here. How do I grab the selected data from a multiple choice drop down html form using php and submit into a database. I need a seperate row for each choice.

I'd be happy just knowing how to grab the data and put it into an array.

+2  A: 

It gets sent into an array, actually!

<form action="myscript.php" method="POST">
<select name="colors[]" multiple="multiple" size="2">
<option>Red</option>
<option>Blue</option>
<option>Green</option>
<option>Orange</option>
</select>
<input type="submit" value="Go!"> 
</form>

Then in the server side, $_POST['colors'] will be an array with the selected values.

The key here is to use the bracket notation in the name to let PHP know to expect an array.

For more, check out the PHP documentation's example.

Once you have the variables, it is trivial to create new rows.

Paolo Bergantino