I am displaying
a table and each row of table have a approve
and reject button
and after clicking on approve the status should reflect to database as approved
.
I tried for it but after clicking on any row's approve button it will set status
as approved for all the rows.
My PHP code is:
$doc_re = "select * from files where receiver='$user'";
$record = mysqli_query($conn,$doc_re);
if($record)
{
echo " <br><center><span class='badge badge-light' style='font-size:30px; background-color:teal;color:white;padding:10px;'>RECEIVED RECORDS</span></center>";
echo "<br><table class='table' border='3' style='background-color:rgba(2,2,2,0.7);'>";
echo "<thead class='thead-dark' >";
echo "<tr style='font-size:23px;'><th style='color:skyblue;'><center>TO</center></th>
<th style='color:skyblue;'><center>FROM</center></th>
<th style='color:skyblue;'><center>FILE</center></th>
<th style='color:skyblue;'><center>MESSAGE</center></th>
<th style='color:skyblue;'><center>APPROVE</center></th>
<th style='color:skyblue;'><center>REJECT</center></th>
<th style='color:skyblue;'><center>STATUS</center></th></tr></thead>";
while($r = mysqli_fetch_array($record,MYSQLI_ASSOC))
{
echo "<tr><td style='color:white; font-size:18px;'><center><strong>{$r['receiver']}</strong></center></td>
<td style='color:white; font-size:18px;'><center><strong>{$r['sender']}</strong></center></td>
<td style='color:white; font-size:18px;'><center><strong><a href='".$r['file']."'>{$r['file']}</a></strong></center></td>
<td style='color:white; font-size:18px;'><center><strong>{$r['message']}</strong></center></td>
<form method='POST'>
<td><center>
<button class='button button1' name='approve' type='submit'><span>✓</span></button></center></td>
<td><center><button class='button button1' style='background-color:red;' name='reject' type='submit'><span>✘</span></button></center></td>
</form>
<td style='color:white; font-size:18px;'><center><strong>{$r['Status']}</strong></center></td>
</tr>";
if(isset($_POST['approve']))
{
$q1 = "update files set Status='APPROVED' where receiver='{$r['receiver']}' and sender='{$r['sender']}' ";
$res = mysqli_query($conn,$q1);
}
elseif(isset($_POST['reject']) )
{
$q2 = "update files set Status='REJECTED' where receiver='{$r['receiver']}' and sender='{$r['sender']}' ";
$ress = mysqli_query($conn,$q2);
}
}
echo "</table>";
}
It set's status as approved for all the rows