I am practicing php by making an approved/reject system, in which administrator approves/rejects student records. It works fine with one row, but with multiple rows fetched from the table either all get approved or all get rejected. What needs to be revised in the following?
<?php
session_start():
?>
<table>
<tr>
<th>ID</th>
<th>Approval</th>
<th>Picture</th>
<th>Status</th>
</tr>
<?php
include "dbconn.php";
$i=1;
$query = "select * from data";
$sql = mysqli_query($conn,$query);
$count = mysqli_num_rows($sql);
if($count>0)
{
while($row=mysqli_fetch_array($sql))
{
?>
<tr>
<td> <?php echo $row['id']; $_SESSION['stuappid']=$row['id'];?> </td>
<td> <?php echo $row['approval']; ?> </td>
<td> <img src ="<?php echo $row['picture']; ?>" height="100px" width="100 px"> </td>
<td>
<form method="post" action="">
<button type="submit" name="approved">Approve</button>
</form>
<form method="post" action="">
<button type="submit" name="rejected" >Reject</button>
</form>
</td>
</tr>
</table>
<?php
$i++;
if(isset($_POST['approved']))
{
$query2 = "update data set approval= 'Approved' where id='".$_SESSION['stuappid']."'";
$sql2 = mysqli_query($conn,$query2);
$query22= "INSERT into approved(id,status) values ('".$_SESSION['stuappid']."','Approved')";
$sql3 = mysqli_query($conn,$query22);
}
if(isset($_POST['rejected']))
{
$query4 = "update data set approval= 'Rejected' where id='".$_SESSION['stuappid']."'";
$sql41 = mysqli_query($conn,$query4);
$query5= "INSERT into rejected(id,status) values ('".$_SESSION['stuappid']."','Rejected')";
$sql51 = mysqli_query($conn,$query5);
}
}
}
else{
echo "No Record";
}