我想在一个php文件中插入来自2个不同表的数据。只会执行第一个插入查询。请帮帮忙,谢谢!
<?php
//session_start();
include('config.php');
//$_SESSION['ID'] = $ID
//Data from guestAdd.php
$aID = $_POST['id'];
$afrom = $_POST['from'];
$ato = $_POST['to'];
$aleaveType = $_POST['leaveType'];
$selectRemarkSql = mysqli_query($conn, "SELECT remarkName FROM remarks WHERE remarkID = '$aleaveType';");
while($row = $selectRemarkSql ->fetch_assoc()) {
$leaveType = $row["remarkName"];
}
$addAbsentSql = mysqli_query($conn, "INSERT INTO absent(afrom, ato, aleaveType, empID) VALUES('$afrom', '$ato', '$leaveType', '$aID');");
$leaveLogUpdateSql = mysqli_query($conn, "INSERT INTO attendance(empID, HoursWorked, remarks, holiday) VALUES('$aID', 00:00:00, '$aleaveType', 'None');")
header("Refresh: viewAllEmployees.php");
?>
答案 0 :(得分:2)
检查查询之间的错误。确保停止标题刷新,以便显示错误消息。
$addAbsentSql = mysqli_query($conn, "INSERT INTO absent(afrom, ato, aleaveType, empID) VALUES('$afrom', '$ato', '$leaveType', '$aID');");
echo myslqi_error($conn);
$leaveLogUpdateSql = mysqli_query($conn, "INSERT INTO attendance(empID, HoursWorked, remarks, holiday) VALUES('$aID', 00:00:00, '$aleaveType', 'None');")
//header("Refresh: viewAllEmployees.php");