'Incrementing PHP variable value by 1 whenever user click submit button
I'm trying this code to increment the complete flag by 1 whenever user click on complete button. I have tried some workarounds but nothing's working.
This is the script which is basically printing the details of students room from a table and looks like this:
Room | LastChecked | Checks this Week | time | AssignedTo
123 | March 14, 22 | 1 | 8.50AM | test123 | |CompleteButton|
The supervisor has to click on complete button to confirm the room checkout.
Script:
<div id="tabs_sections_2">
<p></p>
<?php
$rooms = array_filter($roomInspection, function ($v) {
return $v["Agent"] != 'N/A' and $v["CompletedBy"] == "";
});
echo '<table class="sortable" width="100%">';
echo '<tr><th>Room</th><th>Last Checked</th><th>Checks this week</th><th>Time</th><th>Assigned To</th></tr>';
foreach ($rooms as $room) {
//echo '<tr><td align="left">' . $room['Room'] . '</td><td>' . date('Y-m-d h:i a', strtotime($room['LastChecked'])) . '</td><td>' . $room['WeekChecks'] . '</td>' . '<td>' . date('Y-m-d h:i a', strtotime($room['Time'])) . '</td>' . '<td>' . $room['Agent'] . '</td><td>' . '<button class="buttonBlack complete" type="submit" '<a href="Test.html?ID=' . $i . '"onclick="$(\'#roomId\').val(' . '\'' . $room['Room'] . '\'' . '); $(\'#weekChecks\').val(' . '\'' . $room['WeekChecks'] . '\'' . '); $(\'#id\').val(' . '\'' . $room['Id'] . '\'' . ')";><i class="fas fa-check fa-1x complete"></i> Complete</button>' . '</td>';
$var = $room['sysId'];
$url = 'https://abctest.com/nav_to.do?uri=x_ttuit_cts_checks_cts_checks.do?sys_id=-1%26sysparm_query=u_room_number=' . $var;
echo '<tr><td align="left">' . $room['Room'] . '</td><td>' . date('Y-m-d h:i a', strtotime($room['LastChecked'])) . '</td><td>' . $room['WeekChecks'] . '</td>' . '<td>' . date('Y-m-d h:i a', strtotime($room['Time'])) . '</td>' . '<td>' . $room['Agent'] . '</td><td>' . '<a href ='.$url.' target= "_blank"'.'><button class="buttonBlack complete" name="submit" type="submit" onclick="update(\'' .$room['CompleteStatus']. '\')"
><i class="fas fa-check fa-1x complete"></i> Complete</button></a>' . '</td>';
echo '</table><br><br>';
if ($workday == false) {
echo "<p align='center'><i>No student is scheduled for work today</i></p>";
}
?>
</div>
The value of room['CompleteStatus'] has already been defined 0 for all the rooms.
I'm not sure what to put in update() javascript function to increment this variable value.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
