我无法弄清楚$updateApproval
语句的问题是什么。一切都很好,$_POST
能够从表单中检索数据。当我运行它时,SQL语句在phpMyAdmin上运行良好,替换变量,所以不应该有任何错误。
我是否在不知情的情况下发生冲突,或者我的更新声明无法正常工作?尝试在这里和那里切换,但它只是保持安静,没有任何轻微的错误。我向您提供您需要的信息,如果它很乏味,我很抱歉。任何帮助是极大的赞赏。谢谢。
这是我的数据库:
同意表
consent
-----------------------------------------------------------------------------------------
consent_id | staff_id | approval_id | type_of_leave | consent_date_from | consent_date_to
保留类型表
leavetype
----------------------------
type_of_leave | leave_type |
员工表
staff
------------------------------------------------------------------
staff_id | role_id | staff_name | gender | staff_email | password |
员工离职表
staffleave
----------------------------------------------------------------------
leave_log | staff_id | annual_leave | sick_leave .....//other leaves and so on
表格已经结束了。我实际上已将select option
放入表单中,因此有<td> <tr>
标记。
<td>
<div class="form-group">
<form action="doApproval.php" method="post" name="register">
<input hidden name="getStaffId" value="<?php echo $staffId ?>" >
<input hidden name="getConsentId" value="<?php echo $consentId ?>" >
<input hidden name="getLeaveId" value="<?php echo $leaveId ?>" >
<div class="form-group">
<select class="form-control" onchange="this.form.submit()" id="select" name="getConsentChange">
<option value="1" <?php if ($getCurrentStatus == 1) echo "selected"; ?>>Approve</option>
<option value="2" <?php if ($getCurrentStatus == 2) echo "selected"; ?>>Reject</option>
<option <?php if ($getCurrentStatus == 3) echo "selected"; ?>>Pending</option>
</select>
</div>
<noscript><input type="submit" value="Submit"></noscript>
</form>
</div>
</td>
POST
将在这里结束。保存员工工作天数的查询效果很好,但不能保留休假状态。
$staffId = $_POST['getStaffId'];
$consentId = $_POST['getConsentId'];
$getConsent = $_POST['getConsentChange'];
$getLeaveId = $_POST['getLeaveId'];
$updateApproval = "UPDATE consent SET approval_id = $getConsent WHERE consent.staff_id = '$staffId' AND consent.consent_id = $getConsent"; //Update statement that is not working
$leaveCheckpoint = "SELECT * FROM consent, staffleave, staff WHERE staffleave.staff_id = staff.staff_id
AND staff.staff_id = consent.staff_id AND consent.consent_id = '$consentId'";
$checkpointQuery = (mysqli_query($link, $leaveCheckpoint)) or die("Retrieve checkpoint error " . mysqli_error($link));
if ($checkLeave = mysqli_fetch_array($checkpointQuery)) {
if ($checkLeave['staff_id'] = '$staffId' && $checkLeave['consent_id'] = '$consentId') {
//retrieving the number of leaves staff have took
if ($getLeaveId == 1 && $getConsent == 1) {
$updatedLeave1 = $chkAnnual + $dateDiff;
$recordLeave = "UPDATE staffleave SET annual_leave = '$updatedLeave1' WHERE staff_id = '$staffId'";
} else if ($getLeaveId == 2 && $getConsent == 1) {
$updatedLeave2 = $chkSick + $dateDiff;
$recordLeave = "UPDATE staffleave SET sick_leave = '$updatedLeave2' WHERE staff_id = '$staffId'";
} else if ......// so on when they meet the condition, it works fine and able to insert.
else {
?>
<script type="text/javascript">
alert("No data was updated in the process")
window.location = "manageStaffLeave.php";
</script>
}
<?php
}
$successConsent = mysqli_query($link, $recordLeave) or die("Insert Leave Date Error " . mysqli_error($link));
}
$approvalUpdate = (mysqli_query($link, $updateApproval)) or die("Update error " . mysqli_error($link));
mysqli_close($link);
?>
<!DOCTYPE html>
<body>
if ($approvalUpdate && $successConsent) {
?>
<script type="text/javascript">
window.location = "manageStaffLeave.php";
</script>
<?php
}
?>
</body>
答案 0 :(得分:0)
我想你错过了';'
<input hidden name="getStaffId" value="<?php echo $staffId; ?>" >
<input hidden name="getConsentId" value="<?php echo $consentId; ?>" >
<input hidden name="getLeaveId" value="<?php echo $leaveId; ?>" >
答案 1 :(得分:0)
你犯了一个基本错误:
$checkLeave['staff_id'] = '$staffId' && $checkLeave['consent_id'] = '$consentId
此处您正在影响字符串'$staffId'
到数组$checkLeave['staff_id']
和$consentId
到$checkLeave['consent_id']
删除引号和相等的比较:
$checkLeave['staff_id'] == $staffId && $checkLeave['consent_id'] == $consentId