How do I insert Data Into database with many Input which has same name?

前端 未结 1 425
醉酒成梦
醉酒成梦 2021-01-29 03:34

hello friends I have a form field in which I want to insert data which has four field which are customer_id , field_name1 ,field_name2, field_name3 , The question is I want to

相关标签:
1条回答
  • 2021-01-29 04:01

    Give the repeating fields array-style names:

    <input type="text" name="field_name1[]">
    

    PHP will collect the inputs into arrays, so $_POST['field_name1'] will be an array. Then you can loop over them:

    foreach ($_POST['field_name1'] AS $index => $field1) {
        $field2 = $_POST['field_name2'][$index];
        $field3 = $_POST['field_name3'][$index];
    
        // now you can insert all these values into the DB
    }
    
    0 讨论(0)
提交回复
热议问题