multiple values insertion of checkbox only last value is taking in database

后端 未结 3 1139
自闭症患者
自闭症患者 2021-01-15 19:33

I need to insert more than one values in checkbox but now it is seemed to be only the last value am entering is inserting to database.

this is my HTML code

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-15 20:11

    Your problem is likely:

    You have multiple checkboxes.

    And you want to insert all of them into database.

    You need to loop your posted checkboxes.

    Your problem is likely that you are not looping over the $_POST['product'], so, only, the last product is inserting into database.

    So, your checkboxes:

    ">
    
    

    The code for posted file:

    if (! empty($_POST['product'])) {
     foreach ($_POST['product'] as $product) {
      // Here, you insert $product into database.
     }
    }
    

提交回复
热议问题