,這一問題被創建爲我剛纔的問題中包含的,而不是縮小它下降到1PHP - SQL - 更新數據的按鈕點擊
目的
2問題當用戶選擇三個變量來訪問一個數據,用戶將能夠點擊一個按鈕來改變數據的一個細節。
SQL - 數據庫表(SchoolData)
+-----+--------+------------+------------+----------------+-----------+
| ID | Class | Teacher | YearMonth | Description | Status |
+-----+--------+------------+------------+----------------+-----------+
| 1 | Alpha | Sara | 2017/01 | Good & Clean | Pending |
+-----+--------+------------+------------+----------------+-----------+
| 2 | Alpha | Sara | 2017/01 | Has 30 Chairs | Pending |
+-----+--------+------------+------------+----------------+-----------+
| 3 | Alpha | Sara | 2017/01 | Has 30 Tables | Pending |
+-----+--------+------------+------------+----------------+-----------+
| 4 | Alpha | Sara | 2017/01 | 5 Subjects | Pending |
+-----+--------+------------+------------+----------------+-----------+
| 5 | Beta | John | 2016/11 | Big & Clean | Official |
+-----+--------+------------+------------+----------------+-----------+
| 6 | Beta | John | 2016/11 | New Student | Official |
+-----+--------+------------+------------+----------------+-----------+
| 7 | Beta | John | 2016/11 | Injured Student| Official |
+-----+--------+------------+------------+----------------+-----------+
| 8 | Beta | John | 2016/11 | 6 Subjects | Official |
+-----+--------+------------+------------+----------------+-----------+
頁面
+---------------------------------------------------------------+
| |
| |>Select Class<| |>Select Teacher<| |>Select Year/Month<| |
| |
| (Search) |
| |
| |
|>>>>>>>>>>>>>>>>>>>>>>>>>>INPUT<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<|
| |
| {Class} {Teacher} {Description} |
| |
| |
| (Update) |
| |
+---------------------------------------------------------------+
傳奇
下拉列表 - |> < |
按鈕 - ()
文本輸入 - {}
頁面描述
的更新 butto n會將所選數據的「狀態」更改爲「待處理」。所以,如果讓我們說用戶搜索| Beta |約翰| 2016/11 |並點擊更新按鈕,該數據的「狀態」將從「官方」更改爲「待定」
但是,如果員工搜索「狀態」已經是「待定」的數據,例如,| Alpha |薩拉| 2017/01 |,更新按鈕將被禁用。
HTML表格
<!--Those data are setting for checking data existance in the database -->
<input type="hidden" name="class" value=" <?php echo $class; ?>" >
<input type="hidden" name="date" value=" <?php echo $getDate; ?>">
<input type="hidden" name="teacher" value=" <?php echo $teacher; ?>" >
<input type="hidden" id="inputStatus" name="status" value="">
更新按鈕(HTML)
<td colspan="1" valign="bottom" align="left">
<button type="button" class="btn btn-lg update" id="btnUpdate" name="update"> Enable Re-Submit </button>
</td>
更新按鈕功能(JavaScript的)
$(function(){
$("button#btnUpdate").on('click', function (e){
e.preventDefault();
$("#inputStatus").val("update");
$.ajax({
type: 'post',
url: 'changeClassStatus.php'
});
}
}
changeClassStatus。PHP(PHP)
<?php
$class = trim($_POST['calss']);
$teacher = trim($_POST['teacher']);
$date = $_POST['date'];
$date = $date."/01";
$status = $_POST['status'];
$empId = $_POST['empId'];
if($status == 'update'])){
$sqlUpdate = mysqli_query($conn,"UPDATE SchoolData SET Status='Pending' WHERE (Class=$class AND Teacher=$teacher AND ID='".$id[$i]."' AND YEAR(MonthYear)= YEAR('$date') AND MONTH(MonthYear)= MONTH('$date'));";
$sqlExecute=$conn->query($sqlUpdate)or exit("Error code ({$conn->errno}): {$conn->error}");
echo "Data Status Changed";
}
?>
問題描述
我已經實現了代碼,但他們沒有更新的搜索數據的狀態。當我點擊更新按鈕,沒有更新的數據,並沒有任何反應(沒有變化,並沒有迴應消息)
其他注意事項
這個問題是與PHP - SQL - Disable, Hide or Enable Button based on Data。如果我的問題有任何缺乏或不準確的信息或問題,請告訴我。謝謝
什麼是錯誤? –
在提供的代碼中,不要將任何數據發送到服務器。無需更新/ –
實際上,您需要通過ajax post方法發送所有數據,以便php代碼可以正常工作。您不會發送任何數據 –