Home > Enterprise >  "isset" is not piking up button click
"isset" is not piking up button click

Time:10-08

I'm trying to create delete button, in front of each row in a table. Each button id = value (book_id) taken from a data table. However, when I click the button it does not run the code inside isset function.

   if(mysqli_num_rows($result) > 0)
    {
        echo "<br><br>";
        echo "<table border='1'>";
        echo "<th>BOOK ID</th><th>BOOK NAME</th><th>PRICE</th>";
        while ($row = mysqli_fetch_assoc($result))            
        {                
            echo "<tr>";
                $book_id = $row['book_id'];
                //echo $book_id.'<br>';
                echo "<td>" .$row['book_id']. "</td>";
                echo "<td>" .$row['book_name']. "</td>";
                echo "<td>" .$row['price']. "</td>";
                //echo "<td><a href='edit_user.php?id=""'</a>Edit</td>";
                // echo "<td><a href='db_actions/delete_user.php?id=" .$row['book_id']. "'</a>Delete</td>";
                echo '<td><center><input type="submit" id='.$book_id.' name="Delete" value ="Drop"><center></td><tr>';
            echo "</tr>";
        }
        echo "</table>";

enter image description here

But when I use the following code it does not output anything. What could be the issue?

      if (isset($_POST['Delete'])) 
      {
         $ID = $_GET['id'];
         echo $ID;
      }

CodePudding user response:

You need to wrap a complete form around that button for it to work as a form, also I suggest putting the book_id into a hidden field to get it back to the page script

I also remove the deprecated <centre> tag, use css instead

echo '<td>
            <form action="db_actions/delete_user.php" method="POST">
                <input type="hidden" name="id" value="'.$book_id.'">
                <input type="submit" name="Delete" value ="Drop">
            </form>
    </td>';
  •  Tags:  
  • php
  • Related