PHP与mysqli循环直到条件满足。 当表格中布尔值为0到1时,将重定向到其他页面

Here some my code for see if boolean is 1 then go to google.com.

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");
             }}}

I can't post a comment yet, so I'll show you what I understood from your question.

There are a couple of things I would like to tell you:

  1. You didn't close your if(mysqli_num_rows($result) > 0) statement.
  2. Please make your code easier to read.
  3. Why do you have a for loop when you don't use $i and why does the for loop loop 20 times?
  4. Escape the $_POST variable or use prepared statements to prevent SQL injection.
  5. What does $t_slot_times store?

Here's what I have for you right now:

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");
        }
    }
}

It will be much easier to help you if you could give us more information.