I couldn't figure out what is the problem with $updateApproval
statement. Everything is fine and the $_POST
is able to retrieve the data from the form. SQL statement works well on phpMyAdmin when I run it , substituting the variables so there should not be any mistakes.
Am I conflicting without knowing or there are some other reasons that my update statement is not working? Tried switching here and there but it just kept quiet and no slightest error is out. I provide you the information you need and sorry if it is tedious. Any help is greatly appreciated. Thank you.
This is my database:
Consent Table
consent
-----------------------------------------------------------------------------------------
consent_id | staff_id | approval_id | type_of_leave | consent_date_from | consent_date_to
Leave Type Table
leavetype
----------------------------
type_of_leave | leave_type |
Staff Table
staff
------------------------------------------------------------------
staff_id | role_id | staff_name | gender | staff_email | password |
Staff Leave table
staffleave
----------------------------------------------------------------------
leave_log | staff_id | annual_leave | sick_leave .....//other leaves and so on
The form is over here. I have actually put a select option
into a form, thus there's the <td> <tr>
tag.
<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>
The POST
will be over here. The query that saves the number of days staff take works well, but not the status of their leave.
$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>
I think you missed out ';'
<input hidden name="getStaffId" value="<?php echo $staffId; ?>" >
<input hidden name="getConsentId" value="<?php echo $consentId; ?>" >
<input hidden name="getLeaveId" value="<?php echo $leaveId; ?>" >
You are making a basic mistake :
$checkLeave['staff_id'] = '$staffId' && $checkLeave['consent_id'] = '$consentId
Here you are affecting the strings '$staffId'
to the array $checkLeave['staff_id']
and $consentId
to $checkLeave['consent_id']
Remove quote and and an equal for comparison :
$checkLeave['staff_id'] == $staffId && $checkLeave['consent_id'] == $consentId
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.