I want to delete the rows that I select with my checkbox and also delete the database so that pq is given in this part of the code:
<?php
include "conexao.php";
if (isset($_POST['sel'])) {
foreach ($_POST['sel'] as $id) {
$sql="DELETE FROM lojas WHERE id = $id";
$res=mysqli_query($con,$sql);
}
}else{
echo "form nao submetido";
}
?>
Else is appearing on the screen, ie "not submitted form" and not what is in the case
Here is the whole code:
<form class="customform" method="POST" action="fabrica_conLoja2.php" >
<div class="s-12 l-7">Nome Loja<input name="nloja" placeholder="Nome Loja" type="text" /></div>
<div class="s-12 l-7">Nome Gerente<input name="ngerente" placeholder="Nome Gerente" type="text" /></div>
<div class="s-12"></div>
<div class="s-12 m-6 l-4"><button name="cadastrar" type="submit" value="cadastrar" onclick="">Pesquisar</button></div>
<title></title>
</head>
<body>
<table>
<tr>
<th>Id</th>
<th>Nome Loja</th>
<th>Nome Gerente</th>
<th>Rua</th>
<th>Bairro</th>
<th>Número Estabele.</th>
<th>Estado</th>
<th>Cidade</th>
<th>Telefone</th>
<th>Selecionar</th>
</tr>
<br><br><br><br><br><br><br><br><br>
<?php
include "conexao.php";
$nomeLoja=$_POST["nloja"];//"nloja");
$nomeGerente=$_POST["ngerente"];//"nome_gerente");
$sql = "SELECT * FROM lojas WHERE nome LIKE '%$nomeLoja%' and nome_gerente LIKE '%$nomeGerente%' ";
$res=mysqli_query($con,$sql);
$li = mysqli_num_rows($res);
echo "               $li loja(s) encontrada(s)<br/>";
while ($vloj=mysqli_fetch_row($res)) {
$vid=$vloj[0];
$vnome=$vloj[1];
$vgerente=$vloj[2];
$vrua=$vloj[3];
$vbairro=$vloj[4];
$vnumero=$vloj[5];
$vuf=$vloj[6];
$vcidade=$vloj[7];
$vtel=$vloj[8];
echo"<tr>
<td>$vid</td>
<td>$vnome</td>
<td>$vgerente</td>
<td>$vrua</td>
<td>$vbairro</td>
<td>$vnumero</td>
<td>$vuf</td>
<td>$vcidade</td>
<td>$vtel</td>
<td align = center><input type='checkbox' value='$vid' name='sel[]'></td>
</tr>";
}
?>
</table> <br>
</form>
<form method="POST" action="fabrica_conLoja2.php">
<?php
include "conexao.php";
if (isset($_POST['sel'])) {
foreach ($_POST['sel'] as $id) {
$sql="DELETE FROM lojas WHERE id = $id";
$res=mysqli_query($con,$sql);
}
}else{
echo "form nao submetido";
}
?>