为什么$ _GET在条件下不起作用?

my if condition isn't working with the $_GET['delete'] condition. How to solve this? I'm want to delete a row from a table by reading the url. if the url contains the work delete this the mysql row should be deleted. what is the wrong i'm doing here?

                <?php

                      $query = "SELECT * FROM category";
                      $select_category_id_and_title = mysqli_query($connection, $query);
                      while($row = mysqli_fetch_assoc($select_category_id_and_title) )
                      {
                          $cat_id = $row['id'];
                          $cat_title = $row['cat_title'];
                          echo "<tr>";
                          echo "<td>$cat_id</td>";
                          echo "<td>$cat_title</td>";
                          echo "<td><a href='admin_category_dashboard_new.php?delete = {$cat_id}'>DELETE</a></td>";
                          echo "<td><a href='admin_category_dashboard_new.php?edit = {$cat_title}'>EDIT</a></td>";
                          echo "</tr>";
                          //echo $_GET['delete'];
                      }
                 ?>             
                 <?php 
                    if(isset($_GET['delete'])) // doesn't work
                    {
                        $delete_cat_id = $_GET['delete'];
                        echo '<h1>' . $delete_cat_id . '</h1>';
                        $query = "DELETE FROM category WHERE id = $delete_cat_id ";
                        $Cat_id_delete_query = mysqli_query($connection, $query);
                        if(!$Cat_id_delete_query)
                        {
                            die("error" . mysqli_error($connection));
                        }
                        header("Location: admin_category_dashboard_new.php ");
                    }
                ?>  

You've included a space after 'delete' in your URL.

Thus the $_GET index you would need to look for is 'delete_'

try the following in a file

var_dump($_GET);

then go to yourfile.php?delete = any

then retry with yourfile.php?delete=any

see the difference

If the condition is not firing at all, then it is probably because:

  1. You misspelled delete in your URL.
  2. delete has a null value.

The isset() function returns false even if the value is null; not just if the key doesn't exist.