我有这个查询:
$ManagerName = $mysqli->real_escape_string($_POST['ManagerName']);
$Password = encryptIt($_POST['Password']);
$Address = $mysqli->real_escape_string($_POST['Address']);
$Email = $mysqli->real_escape_string($_POST['Email']);
$PhoneNo = $mysqli->real_escape_string($_POST['PhoneNo']);
$OfficeName = $mysqli->real_escape_string($_POST['OfficeName']);
$ConsignmentNo = $_POST['percel'];
$status = 'In Transit';
$det = explode(",",$ConsignmentNo);
$sql = "INSERT INTO tbl_courier_officers (officer_name, off_pwd, address, email, ph_no, office, consignment, status, reg_date)
VALUES ('$ManagerName', '$Password', '$Address', '$Email', '$PhoneNo', '$OfficeName','$ConsignmentNo','$status', NOW())";
$done = mysqli_query($mysqli, $sql);
if($done){
echo "added";
foreach($det as $valuez)
{
$m = $Email;
mysqli_query($mysqli,"INSERT INTO courier_track (email, percel_num) values('$m', '$valuez')");
}
mysqli_query($mysqli, "insert into user_log (username,name,action,time, user_id, mydate, mtime)values('$uname','$fullname','Added $ManagerName to courier officers table', '$tv', '$id', '$t', '$tv')");
}else{
echo 'Error occured: '.$mysqli->error;
}
第一次插入为真后,我要提交第二个查询,这是一个 foreach循环。我希望它提交出现值的次数,但第一次插入后不提交。
除 foreach 中的查询外,所有查询均有效。
有人可以告诉我该怎么做吗?
答案 0 :(得分:1)
更改这段代码
mysqli_query($mysqli,"INSERT INTO courier_track (email, percel_num) values('$m', '$valuez')");
具有如下错误通知
mysqli_query($mysqli,"INSERT INTO courier_track (email, percel_num) values('$m', '$valuez')") or die(mysqli_error($mysqli));
然后您将了解insert语句中的错误。
如果不起作用,请输入print_r($ det);并将其添加到OP中,以便我们可以正确地找出问题