2 回答
TA贡献2021条经验 获得超8个赞
您在循环内分配变量,但在循环后仅插入一次数据库。将您的数据库插入放入循环中,如下所示(为了更好地理解这个想法,我保持简短):
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 关注
- 191 浏览
添加回答
举报