duan0714 2016-04-08 04:43
浏览 14
已采纳

为什么$ _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 ");
                    }
                ?>  
  • 写回答

2条回答 默认 最新

  • dorisdong0514 2016-04-08 05:09
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀