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.
找不到有关如何做到这一点的任何好信息所以我想我会在这里添加它。如何使用php从多选下拉html表单中获取所选数据并提交到数据库中。每个选择我需要一个单独的行。
I'd be happy just knowing how to grab the data and put it into an array.
我很高兴知道如何获取数据并将其放入数组中。
1 个解决方案
#1
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.
然后在服务器端,$ _POST ['colors']将是一个包含所选值的数组。
The key here is to use the bracket notation in the name to let PHP know to expect an array.
这里的关键是在名称中使用括号表示法让PHP知道期望一个数组。
For more, check out the PHP documentation's example.
有关更多信息,请查看PHP文档的示例。
Once you have the variables, it is trivial to create new rows.
获得变量后,创建新行很简单。
#1
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.
然后在服务器端,$ _POST ['colors']将是一个包含所选值的数组。
The key here is to use the bracket notation in the name to let PHP know to expect an array.
这里的关键是在名称中使用括号表示法让PHP知道期望一个数组。
For more, check out the PHP documentation's example.
有关更多信息,请查看PHP文档的示例。
Once you have the variables, it is trivial to create new rows.
获得变量后,创建新行很简单。