This Question was created as my previous question contained 2 question instead of narrowing it down to 1
Aim
When the user selects three variables to access a data, the user will then be able to click on a button to change one of the particulars of that data.
SQL - Database Table (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 |
+-----+--------+------------+------------+----------------+-----------+
Webpage
+---------------------------------------------------------------+
| |
| |>Select Class<| |>Select Teacher<| |>Select Year/Month<| |
| |
| (Search) |
| |
| |
|>>>>>>>>>>>>>>>>>>>>>>>>>>INPUT<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<|
| |
| {Class} {Teacher} {Description} |
| |
| |
| (Update) |
| |
+---------------------------------------------------------------+
Legend
Drop down List - |><|
Button - ()
Text Input - {}
Webpage Description
The Update button will change the "Status" of the selected data to "Pending". So if lets say the user searches for | Beta | John | 2016/11 | and clicks on the Update button, the "Status' for that Data will be changed from "Official" to "Pending"
But if the staff searches for a data which "Status' is already "Pending" for example, | Alpha | Sara | 2017/01 |, the Update button will be disabled.
HTML Table
<!--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="">
Update Button (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>
Update Button Function(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";
}
?>
Problem Description
I have implemented the codes but they are not updating the status of the searched data. When I do click on the Update button, the data is not updated and nothing happens (No Changes and No Echo Message)
Additional Notes
This question is linked to PHP - SQL - Disable, Hide or Enable Button based on Data. If there are any lacking or inaccurate information or problems with my question, please let me know. Thank you
$conn->query($sqlUpdate)will give you an error, since you already executed the query in the line before, and you are executing an update, somysqli_queryreturns a boolean.