Ir ao conteúdo
  • Cadastre-se

PHP Deletar multiplas rows usando checkbox em php e mysql


Posts recomendados

0votar contrafavorita

Estou querendo deletar as rows que eu selecionar com o meu checkbox e deletar também no banco de dados so que ta dando porque nessa parte do código :

 

 

    <?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";
               }
               ?>

   

 

 

Está aparecendo na tela o Else ou seja "form nao submetido" e não o que ta no if

Aqui o código inteiro:

<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 " &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp $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>

     <?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";
               }
               ?>

      <input style=""  type="submit" name="btexcluir" value="Excluir" />


 

 

 

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...