0
I’m having a problem changing the status of users of my database , when I will change the status of some user it does not approve the user of that line and yes last user what can be?
php log.
<?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");
}
}
We’re missing a
</form>
in the first block, it is good to correct this before proceeding with the tests. Then you can dry this code well by making a form just for everything and taking the Hidden, but before you can make it work the way you know, not to complicate too much. Then, just take out the Hidden fields, and use the user ID in Buttons value approves and disapproves.– Bacco
I am voting to close, because it is a typo, and the answers do not solve the problem of the code, besides containing incorrect statements, disturbing other users. See proof of operation with names repeated here: http://codepen.io/bacco/pen/BzkBPy
– Bacco