-1
So, I’m a beginner in PHP and I have a question in the following code... when I click the remove button it doesn’t just remove the id from the back of the while, it removes all, anyone could help me?
<?php
include 'conexao.php';
session_start();
?>
<html>
<head>
</head>
<body>
<h1>CRUD - ALUNOS</h1>
<form action="FrmCadastro.php" method="POST">
<input type="submit" value="+"/>
</form>
<table border="2px">
<th>Aluno</th>
<th>Nota</th>
<th>Turma</th>
<tr></tr>
<?php
$sql = "SELECT * from tbAluno";
$listarAlunos = mysqli_query($conexao, $sql);
while($row = mysqli_fetch_assoc($listarAlunos)){
$id = $row['id'];
$nome = $row['aluno'];
$nota = $row['nota'];
$turma = $row['turma'];
?>
<td>
<?php echo"$nome"?>
</td>
<td>
<?php echo"$nota"?>
</td>
<td>
<?php echo"$turma"?>
</td>
<td>
<form>
<input type="submit" value="remover"/>
<?php
$sql = "DELETE from tbAluno WHERE id = $id";
$removerAluno = mysqli_query($conexao, $sql);
echo $id;
?>
</form>
</td>
<tr></tr>
<?php
}
?>
</table>
</body>
</html>
The DELETE code is running for each user you selected in the query. To make the code run only when you click the button, you would need to make a form Handling
– João Pedro Henrique