I have this query:
$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;
}
After the first insertion is true, I want to submit the second query which is a foreach loop. I want it to submit the number of time the values occurs but it is not submitting after the first insertion.
All queries are working except for the query in the foreach.
Can someone please tell me what to do?
mysqli_queryreturns false on failure. Check for that. If it is false, checkmysqli_error(php.net/manual/en/mysqli.error.php). Error will tell you what went wrong.