为什么$ _GET如果条件不能在里面工作?

时间:2016-04-08 04:43:38

标签: php get

我的if条件不适用于$ _GET ['删除']条件。怎么解决这个?我想通过阅读网址从表中删除一行。如果url包含工作删除,则应删除mysql行。我在这里做错了什么?

                <?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 个答案:

答案 0 :(得分:1)

您删除了&#39;之后的空格。在您的网址中。

因此,您需要查找的import java.util.*; import java.util.Scanner; import java.util.Random; public class Game { public static void main (String[] args){ int NumberofRoundsPlayed; int NumberofRoundsWonbyHuman = 0; Scanner Keyboard = new Scanner (System.in); System.out.println("DO YOU WANT TO PLAY ROCK PAPER SCISSORS- Y/N"); String HumanPlaying = Keyboard.nextLine(); if(HumanPlaying.equals("No")) { System.out.println("Game Over"); System.exit(0); } int Paper = 1; int Scissor = 2; int Rock = 3; int HumanSelection; int humanroundsWon =0; System.out.println("HOW MANY ROUNDS DO YOU WANT TO PLAY"); NumberofRoundsPlayed = Keyboard.nextInt(); while (NumberofRoundsPlayed < NumberofRoundsPlayed++) { Scanner Computer = new Scanner (System.in); Random rand = new Random(); int ComputerChoice =Computer.nextInt()+1; System.out.println(ComputerChoice); System.out.println("Select 1 for Paper, 2 for Scissor or 3 for Rock"); HumanSelection = Keyboard.nextInt(); //SEE WHO WINS if (ComputerChoice== 1) { if (HumanSelection==1) { System.out.println("Computer and Human Have Tied"); } else if (HumanSelection==2) { System.out.println("Person Wins"); humanroundsWon++; } else if (HumanSelection==3) { System.out.println("Computer Wins"); } } else if (ComputerChoice==2) { if (HumanSelection==1) { System.out.println("computer Wins"); } else if (HumanSelection==2) { System.out.println("Computer and Person Have Tied"); } else if (HumanSelection==3) { System.out.println("Person Wins"); humanroundsWon++; } } else if (ComputerChoice==3) { if (HumanSelection==1) { System.out.println("Person Wins"); humanroundsWon++; } else if (HumanSelection==2) { System.out.println("Computer Wins"); } else if (HumanSelection==3) { System.out.println("Tie"); } } } System.out.println("Game Over"); System.exit(0); } } 索引为$_GET

在文件

中尝试以下操作
'delete_'

然后转到yourfile.php?delete = any

然后使用yourfile.php?delete = any

重试

看到差异

答案 1 :(得分:0)

如果条件根本没有触发,则可能是因为:

  1. 您在网址中拼写错误。
  2. delete具有空值。
  3. 即使值为null,isset()函数也返回false;不仅仅是钥匙不存在。

相关问题