Unable to insert data from dynamically created add remove fields in database using php

后端 未结 2 568
囚心锁ツ
囚心锁ツ 2020-12-21 23:36

I\'m trying to insert data from dynamically created add remove fields in database using php but unable to do.I\'m only able to insert data from original form.

My fo

相关标签:
2条回答
  • 2020-12-22 00:16

    Because you have a header the code will insert single row and do the header to the requested file. So, remove both the header.

    0 讨论(0)
  • You assign variables within a loop, but insert into database only once after the loop. Put your database insertion into the loop, as follows (I keep it short for better understanding of the idea):

    for ($i=0; $i < count($_POST['ch_direction']); $i++ ) { // Here you start each loop
        $ch_direction = trim($_POST["ch_direction"][$i]);
        $ch_direction_through = trim($_POST["ch_direction_through"][$i]);
        $reg_id= $_POST['reg_id'][$i];
        $sql = "INSERT INTO bps_registration_charkilla (ch_direction, ch_direction_through,reg_id) VALUES (?, ?, ?)";   
        ...
        if($stmt = mysqli_prepare($conn, $sql)) ... // Here you prepare the statement for the current element in the loop
        ...
        if(mysqli_stmt_execute($stmt)) ... // Here you actually insert current loop element into the database
        ...
    } // End of the loop
    
    0 讨论(0)
提交回复
热议问题