2 回答

TA貢獻2021條經(jīng)驗 獲得超8個贊
您在循環(huán)內(nèi)分配變量,但在循環(huán)后僅插入一次數(shù)據(jù)庫。將您的數(shù)據(jù)庫插入放入循環(huán)中,如下所示(為了更好地理解這個想法,我保持簡短):
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
- 2 回答
- 0 關注
- 225 瀏覽
添加回答
舉報