Delete a row in DB

1

I'm having trouble with a small code with delete button. I've tried it in some ways but I have not been able to make the button with $deletar do the delete function.

Following code shows each slide and wanted to delete button.

<?php       
        $sql = mysql_query("SELECT * FROM slider");
        while($linha = mysql_fetch_array($sql)){

            $id = $linha['id'];
            $imagem = $linha['imagem'];
            $comentario = $linha['comentario'];
            $link = $linha['link'];
    ?>
  <tr>
    <td><img src="pages/<?= $imagem ?>" width="150px" height="100px"></td>
    <td class="mailbox-name">
      <?= $comentario ?>
    </td>
    <td class="mailbox-subject">
      <?= $link ?>
    </td>

    <td class="mailbox-date">
      <input type="button" class="btn btn-danger" src="<?= $deletar ?>" value="Excluir">
    </td>
  </tr>
  <?php }    ?>     
    
asked by anonymous 20.07.2017 / 13:46

1 answer

0

Your code is wrong, follow it corrected

<?php       
        if(isset($_GET['acao'])){
            $del = mysql_query("DELETE FROM slider WHERE id = '$_GET['id']'")
        }
        $sql = mysql_query("SELECT * FROM slider");
        while($linha = mysql_fetch_array($sql)){

            $id = $linha['id'];
            $imagem = $linha['imagem'];
            $comentario = $linha['comentario'];
            $link = $linha['link'];
    ?>
  <tr>
    <td><img src="pages/<?= $imagem ?>" width="150px" height="100px"></td>
    <td class="mailbox-name">
      <?= $comentario ?>
    </td>
    <td class="mailbox-subject">
      <?= $link ?>
    </td>

    <td class="mailbox-date">
       <a href="id=<?= $deletar; ?>">Deletar</a>
    </td>
  </tr>
  <?php }    ?> 

Remembering that href that will execute your action, if you want to execute the code in another page (the code that excludes), it would be <a href="pagina.php?acao=deletar&id=<?= $id; ?>">Deletar</a> and so on.

    
20.07.2017 / 14:35