I created a delete button that is on the line of every record I'm displaying in a table, but when I click on it and display the delete screen, I realize that the last record in the table is always selected regardless of which item I click. Below is my code, thanks for solution suggestions!
Exclusion screen:
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<form role="form" method="POST" action="php/excluir.php">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Excluir </h4>
</div>
<div class="modal-body">
Você tem certeza que deseja excluir?
<?php
$result = mysqli_query($conexao, "SELECT id FROM itens WHERE descricao = 'descricao'");
while($exibir = mysqli_fetch_array($result)){
$id = $exibir['id'];
echo '<input type="hidden" name="id" value="' . $id . '"/>';
}
?>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button" data-dismiss="modal">Não</button>
<button class="btn btn-warning" type="submit">Sim</button>
</form>
</div>
</div>
</div>
</div>
delete.php
<?php
$id = $_POST['id'];
$conexao = mysqli_connect('', '', '', '');
if (!$conexao) {
echo "<script> window.location.replace('../erro.html'); </script>";
}
$result = mysqli_query($conexao, "DELETE from itens WHERE id = '$id'");
$result = mysqli_query($conexao, "DELETE from tabela WHERE id = '$id'");
if ($result) {
echo "<script> window.location.replace('../home.php'); </script>";
}else{
echo "<script> window.location.replace('../erro.html'); </script>";
}
mysqli_close($conexao);