无法从SELECT OPTION检索的表单更新数据库


Unable to update database from form retrieved by SELECT OPTION

我不知道$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>

我想你错过了';'

<input hidden name="getStaffId" value="<?php echo $staffId; ?>" > 
<input hidden name="getConsentId" value="<?php echo $consentId; ?>" > 
<input hidden name="getLeaveId" value="<?php echo $leaveId; ?>" >

您犯了一个基本错误:

$checkLeave['staff_id'] = '$staffId' && $checkLeave['consent_id'] = '$consentId

这里您正在影响字符串'$staffId'到数组$checkLeave['staff_id']$consentId$checkLeave['consent_id']

删除引号和等号进行比较:

$checkLeave['staff_id'] == $staffId && $checkLeave['consent_id'] == $consentId