I am having a problem when changing the status of the users of my database, when I am going to change the status of some user it does not approve the user of that line but last user what can be?
logado.php
<?php
//Consulta
$buscarusuario=$pdo->prepare("SELECT * FROM usuario");
$buscarusuario->execute();
//atribuindo dados á variavel
$linha = $buscarusuario->fetchAll(PDO::FETCH_ASSOC);
//percorrendo a variavel para listar os dados
foreach ($linha as $listar) {
$iduser = $listar['id'];
echo "<tr>";
echo " <td>".$listar['id']."</td>";
echo "<td>".$listar['nome']."</td>";
if($listar['status'] > 0 ){
echo "<td class='success text-success'>Aprovado
<form method='post' action='pg/mudastatus.php'>
<input type='hidden' name='desaprovauser' value='$iduser'>
<button type='submit' class='btn btn-xs btn-success alinha-btn' name='desaprova' value='desaprovar'>Desaprovar</button>
</td>";
}else{
echo "<td class='danger text-danger'> Aguardando aprovação
<form method='post' action='pg/mudastatus.php'>
<input type='hidden' name='aprovauser' value='$iduser'>
<button type='submit' class='btn btn-xs btn-danger alinha-btn' name='aprova' value='aprovar' >Aprovar</button>
</form>
</td>";
}
}
?>
mudastatus.php
if(isset($_POST['aprova'])){
$atualizarstatus = $pdo->prepare("UPDATE usuario SET status=1 WHERE id='".$_POST["aprovauser"]."' ");
$atualizarstatus->execute();
$linha = $atualizarstatus->rowCount();
if($linha > 0){
header("location:../logado.php");
}else{
echo "Erro ao Mudar status";
}
}elseif (isset($_POST['desaprova'])){
$atualizarstatus = $pdo->prepare("UPDATE usuario SET status=0 WHERE id='".$_POST["desaprovauser"]."' ");
$atualizarstatus->execute();
$linha = $atualizarstatus->rowCount();
if($linha > 0){
header("location:../logado.php");
}else{
echo "Erro ao Mudar status";
header("location:../logado.php");
}
}