0

código não apresenta nenhum erro mas mesmo assim não executa o DELETE.

Criei uma tag para apagar linha a linha e usei GET para isso e mesmo assim não está a funcionar.

tag <td><a href="delete_rows.php?del=$row[ISBN]">delete</a></td>

metodo GET:

<?php
include_once('config.php');
if( isset($_GET['del']) )
{
    $ISBN = $_GET['del'];
    $sql= "DELETE FROM books WHERE ISBN='$ISBN'";
    $res= mysqli_query($conn,$sql) or die("Failed".mysqli_error($conn));
    echo "<meta http-equiv='refresh' content='0;url=update.php'>";
}    
?>

Edito para adicionar o código completo onde se encontra a tag

<html>
<head>
<title></title>
    <link rel="stylesheet" type="text/css" href="stylesheet.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
    <script>

        function updateBook(id)
        {    
            var isbn = document.getElementById("ISBN"+id).innerHTML;
            document.getElementById("ISBN").value = isbn;

             var title = document.getElementById("Title"+id).innerHTML;
            document.getElementById("Title").value = title;

             var authorsname = document.getElementById("Authorsname"+id).innerHTML;
            document.getElementById("Authorsname").value = authorsname;

             var edition = document.getElementById("edition"+id).innerHTML;
            document.getElementById("edition").value = edition;

             var year = document.getElementById("year"+id).innerHTML;
            document.getElementById("year").value = year;

             var category = document.getElementById("category"+id).innerHTML;
            document.getElementById("category").value = category;

             var publisher = document.getElementById("publisher"+id).innerHTML;
            document.getElementById("publisher").value = publisher;

             var quantityinstock = document.getElementById("quantityinstock"+id).innerHTML;
            document.getElementById("quantityinstock").value = quantityinstock;

             var price = document.getElementById("price"+id).innerHTML;
            document.getElementById("price").value = price;
        }

        $(document).ready(function(){
            $(".update").click(function(){
                $("#UPDT").toggle();
                $(this).text(function(i,text){
                    return text === "See less" ? "Update" : "See less";
                });
            });
        });
    </script>



</head>
    <body>
<?php
    include('config.php');
    $query = "SELECT * FROM books ORDER BY Title ASC";
    $r=mysqli_query($conn, $query);
?>
    <table cellpadding="2" cellspacing="2" border="0">
        <tr>
    <th>ISBN</th>
    <th> Title </th>
    <th> Author's name</th>
    <th> edition</th>
    <th> year</th>
    <th> category</th>
    <th> publisher</th>
    <th> quantity-in-stock</th>
    <th> price</th>
    </tr>
<?php $id = 0;?>
<?php while($books =mysqli_fetch_object($r)){?>
    <?php $id = $id +1;?>
    <tr>
    <td id="ISBN<?php echo $id ?>"> <?php echo $books->ISBN; ?></td>
    <td id="Title<?php echo $id?>"> <?php echo $books->Title;  ?></td>
    <td id="Authorsname<?php echo $id?>"> <?php echo $books->Authorsname; ?></td>
    <td id="edition<?php echo $id?>"> <?php echo $books->edition;?></td>
    <td id="year<?php echo $id?>"><?php echo $books->year;   ?></td>
    <td id="category<?php echo $id?>"> <?php echo $books->category;   ?></td>
    <td  id="publisher<?php echo $id?>"><?php echo $books->publisher;  ?></td>
    <td id="quantityinstock<?php echo $id?>"> <?php echo $books->quantityinstock; ?></td>
    <td id="price<?php echo $id?>"> <?php echo $books->price; ?></td>
    echo '<img src="data:image/jpeg;base64,'.base64_decode( $books->Image ).'">';
    <td> <button class="update" onclick="updateBook(<?php echo $id?>)">Update</button></td> 
        <td><a href="delete_rows.php?del=$row[ISBN]">delete</a></td>
  </tr>
    <?php } ?>
        </table>

        <form id="UPDT" name="updateform" action="update_books.php" method="POST">

            ISBN:<input type="text" name="ISBN" id ="ISBN" value="<?php echo $books->$ISBN;?>">
            Title:<input type="text" name="Title"  id="Title" value="<?php echo $books->$Title;?>">
            Author's name<input type="text" name="Authorsname" id="Authorsname" value="<?php echo $books->$Authorsname;?>">
            Edition<input type="text" name="edition" id="edition" value="<?php echo $books->$edition;?>">
            Year:<input type="text" name="year" id="year" value="<?php echo $books->$year;?>"> 
            Category: <input type="text" name="category" id ="category" value="<?php echo $books->$category;?>">
            Publisher:<input type="text" name="publisher" id="publisher"  value="<?php echo $books->$publisher;?>">
            Quantity-in-stock:<input type="text" name="quantityinstock" id ="quantityinstock" value="<?php echo $books->$quantityinstock;?>">
            Price:<input type="text" name="price" id="price" value="<?php echo $books->$price;?>">
            <input type="submit" value="Send" name="send">
        </form>

    </body>
</html>

Tem como alguém ajudar por favor!

14
  • Qual o valor da variavel $row[ISBN], e como o link fica? 20/04/2017 às 0:30
  • não sei se entendi bem a tua pergunta, vou tentar responder o valor da variavel $row[ISBN] é $ISBN o link simplesmente diz "apagou com sucesso" mas na realidade não apagou nada 20/04/2017 às 0:34
  • 1
    Acho que seu erro está aqui, <td><a href="delete_rows.php?del=$row[ISBN]">delete</a></td>, ele ta interpretando a variavel $row['ISBN'], como um texto normal, tente: <td><a href="delete_rows.php?del=<?php echo $row['ISBN'];?>">delete</a></td> 20/04/2017 às 0:46
  • 1
    Vamos continuar a discussão no chat - chat.stackexchange.com/rooms/57375/problema-php-delete 20/04/2017 às 1:49
  • 2
    Consigo ver o que voces falam mas não consigo responder! fala po anderson que deu certo e ta funcionando VALEUUU 20/04/2017 às 2:29

0

Você deve fazer log-in para responder a esta pergunta.

Pesquise outras perguntas com a tag .