在foreach中插入查询不插入

qncylg1j  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(340)

我有个问题:

$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;
    }

在第一次插入为true之后,我要提交第二个查询,它是foreach循环。我希望它提交值发生的次数,但它在第一次插入后不提交。
除foreach中的查询外,所有查询都在工作。
有人能告诉我该怎么办吗?

vfh0ocws

vfh0ocws1#

更改这段代码

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语句中的错误。
如果不起作用,就打印一张纸($det);把它加到运算表上,这样我们就能正确地解决问题

相关问题