PHP Multiple Dropdown Box Form Submit To MySQL

后端 未结 1 953
情深已故
情深已故 2021-01-20 15:52

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

相关标签:
1条回答
  • 2021-01-20 16:09

    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.

    0 讨论(0)
提交回复
热议问题