简体   繁体   中英

PHP Multiple Dropdown Box Form Submit To MySQL

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM