Getting data from a multiple select dropdown with PHP to insert into MySQL

后端 未结 2 1677
死守一世寂寞
死守一世寂寞 2021-01-23 22:51

I have a list of days in my database created with the SET datatype.

SET(\'Mon\',\'Tue\',\'Wed\',\'Thr\',\'Fri\',\'Sat\',\'Sun\')

相关标签:
2条回答
  • 2021-01-23 23:36

    First, Your select should have name with square brackets:

    <select name='days[]' id='days' size=4 multiple="multiple">
    

    This way when a user select more values (options) and submit the form You will receive an array of values he selected.

    Then You have to loop through this array and insert each record:

    foreach($_POST['days'] as $k => $v) {
        // here do the INSERT query with value $v
    }
    

    But Your query under the select box is telling us that this is not the end of the story...

    0 讨论(0)
  • 2021-01-23 23:56
    foreach ($_POST['days'] AS $key => $value) {
      // INSERT ... where $value is one of the values
    }
    
    0 讨论(0)
提交回复
热议问题