I am trying to update a table in my database with PHP.
I used a loop to get all of the data from the table. Then, adding an "Approve" button in front of each row where the user can click if they want to approve the request, which would change the status to Approved.
Now I'm stuck, I can't find a way to update the Status field and I am not good with JavaScript.
I thought about making the button name dynamic, but I couldn't.
Output image
This is the loop code:
while($row = mysqli_fetch_array($result))
{
echo "<tr bgcolor='#cccccc'>";
echo "<td>" . $row['nursename'] . "</td>";
echo "<td>" . $row['dr'] . "</td>";
echo "<td>" . $row['natureofreq'] . "</td>";
echo "<td>" . $row['clinic'] . "</td>";
echo "<td>" . $row['clinicfloor'] . "</td>";
echo "<td>" . $row['qitem'] . "</td>";
echo "<td>" . $row['moreinfo'] . "</td>";
echo "<td>" . $row['user_check'] . "</td>";
echo "<td>" . $row['id'] . "</td>";
echo "<td bgcolor='#009FE3'>" . $row['rstatus'] . "</td>";
echo '<form name="submit" method="post" action="">';
echo "<td>" . '<button id="approve" name="approve"> Approve</button>' . "</td>";
echo '</form>';
echo "</tr>";
}
This is the update code, which is not working:
$id=$row['id'];
if(isset($_POST['approve']))
{
$allowed = mysqli_query($n," UPDATE newrequest SET rstatus = 'Approved' WHERE id = '$id' ");
}
I would appreciate any help.
$id = $_POST['id'];... if I understand what you’re trying to do, I guess you need to fetch whatever you send in the form... but$rowis not set in the second code. Also, actually send it, because I think you are not. In other words, I’m assuming your update code is somewhere else because it should be... after all.