我在下面有下面的代碼;多個隊列只有最後一個正在執行
$sql = "SELECT * FROM tbl1 where id_no = '$id_no'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$new = $row['full_name'];
header("location:new.php?msg=ID Number $id is already
Registered");
}
} else {
$created = date('jS \ F Y h:i:s A');
$tr_no = 'TR_'.rand(10000,99999).'/'.date(Y).'';
include '../db_config/connection.php';
//update tables
$sql = "INSERT INTO tbl2 (id,vehicle_id,policy_id,insured_by,insurance_co,value_insured,start_date,end_date,created)VALUES ('$tr_no','$reg_no','$p_id','$user_index','$co_id','$value_insured','$start_date','$end_date','$created')" ;
$sql = "UPDATE tbl1 SET updated='1' WHERE item_id = '$reg_no'";
$sql = "INSERT INTO tbl3 (doc_number,value,date,reg_no) VALUES('$tr_no','-$value_insured','$created','$reg_no'";
if ($conn->query($sql) === TRUE) {
header("location:new_insurance.php?message=ENTRIES SUCCESSFULLY POSTED");
} else {
$error = $conn->error;
header("location:new_client.php?err=$error");
}
$conn->close();
}
$conn->close();
?>
包含插入和更新查詢的最後一位是我們遇到問題的地方。而不是執行所有這三個查詢,只執行最後一個查詢。我應該包括哪些修改?
你重寫'$ sql'的內容。你不用連接它 – Jens
你使用哪個API? 'mysqli_'或'PDO'? – Jens
你需要使用'mysqli_multi_query()'。閱讀http://php.net/manual/en/mysqli.multi-query.php – Saty