I'm trying to create a delete button for a table. The exclusion will be ugly in two steps: 1. click on the trash 2. confirm
I think I'm getting confused when it comes to passing the $ pro modal value.
<html lang="en">
<head>
<title>Estoque</title>
<!-- Bootstrap core CSS -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap theme -->
<link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet">
<script src="bootstrap/js/bootstrap.min.js" </script>
<script src="jquery-2.1.4.min.js"</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<table class="table">
<tr><b>
<td>Código Produto</td>
<td>Descrição</td>
<td>Preço</td>
<td>Quantidade Estoque</td>
</tr></b>
<?php
REQUIRE_ONCE "conexao.php";
$sql = "SELECT id, cod_produto, dsc_produto, preco_produto, qtd_estoque, qtd_limitador FROM estoque";
$result = mysqli_query($conexao, $sql);
while ($row = mysqli_fetch_assoc($result)){
?>
<tr bgcolor="<?php echo $bg ?>">
<td><?php echo $row[cod_produto] ?></td>
<td><?php echo $row[dsc_produto] ?></td>
<td><?php echo $row[preco_produto] ?></td>
<td><?php echo $row[qtd_estoque] ?></td>
<td><?php echo $row[qtd_limitador] ?></td>
<td>
<form method="get" action="edit.php">
<button type="hidden" name="id" class="btn btn-default" value="<?php echo $row[id]?>"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> </button>
</form>
<form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>">
<button type="button" name="botaoDelete" class="btn btn-default" data-toggle="modal" value="<?php echo $row[id] ?>" data-target="#myModal"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
</form>
</td>
</tr>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Excluir produto</h4>
</div>
<div class="modal-body">
<p>Você tem certeza que deseja excluir?</p>
</div>
<div class="modal-footer">
<form method="POST">
<button type="button" name="botaoConfirma" value="<?php echo $dlt ?>" class="btn btn-danger">Excluir</button>
<button type="button" class="btn btnn-default" data-dismiss="modal">Fechar</button>
</form>
<?php
if (isset($_POST["botaoDelete"])) {
$dlt = $_POST["botaoDelete"];
if (isset($_POST["botaoConfirma"])) {
$cnf = $_POST["botaoConfirma"];
$deleteSql = mysqli_query($conexao, "DELETE * FROM estoque WHERE id='".$cnf."'");
}
}
}
?>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</tbody>
</div>
</body>
Is there any way to pass button value without using form ? And also, how can I call this value (if the button is pressed) without using if (isset) ? Is it worth it?