Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"isset" is not piking up button click

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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>';
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading