0
I created a delete button that sits on the row of each record that I am displaying in a table, but when I click on it and display the delete screen, I realize that the last record of the table is always selected, regardless of the item that I click. Below follows my code, thank you 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);
Is 1 modal for 1 record ? Or 1 modal for multiple records ?
– Alisson Acioli
The modal is for the selected record, only 1
– R.Gasparin