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 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流