3

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.

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.