2017-06-20 18 views
-4

这里有一些代码用于查看布尔值是否为1,然后转到google.com。PHP与mysqli循环,直到条件满足。当表格页面中的布尔值为0到1时,将重定向到其他页面

if(isset($_POST['submit'])) 
     { 
      $acc_num = $_POST['acc_num']; 
     } 
     $sql = "SELECT * FROM security_protocol WHERE acc_num='$acc_num'"; 
     $result = mysqli_query($con, $sql); 
     if (mysqli_num_rows($result) > 0) { 
      // output data of each row 
      while($row = mysqli_fetch_assoc($result)) { 
       $boolean =$row["boolean"]; 
     if($boolean > 1) { 
      $t_slot_times = $t_slot_time + 1; 
      for ($i = 1;$i<=20;$i++) 
      { 
       header("Location: google.com"); 
      }}} 
+3

问题是? – Jens

+1

了解准备好的语句以防止SQL注入 – Jens

回答

0

我还不能发表评论,所以我会告诉你我从你的问题中了解到什么。

有一对夫妇的事情,我想告诉你:

  1. 你没有关闭if(mysqli_num_rows($result) > 0)声明。
  2. 请让您的代码更易于阅读。
  3. 为什么在不使用$i时有for循环,for循环为什么要循环20次?
  4. 转义$_POST变量或使用预准备语句来防止SQL注入。
  5. $t_slot_times是什么储存?

这是我对你的现在:

if(isset($_POST['submit'])) { 
    $acc_num = $_POST['acc_num']; 
    $acc_num = mysqli_real_escape_string($acc_num); 
} 

$sql = "SELECT * FROM security_protocol WHERE acc_num='$acc_num'"; 
$result = mysqli_query($con, $sql); 

if (mysqli_num_rows($result) > 0) { 
    // Go trough the received data 
    while($row = mysqli_fetch_assoc($result)) { 
     $boolean = $row["boolean"]; 

     if($boolean == 1) { 
      $t_slot_times = $t_slot_time + 1; 

      header("Location: google.com"); 
     } 
    } 
} 

这将是更容易帮助你,如果你可以给我们更多的信息。

+0

感谢您的回答,我通过AJAX完成了此操作。 –

相关问题