2013-07-27 66 views
0

我有這樣PHP驗證

第一循環碼數有多少職位的數組:

for($i = 0; $i < $jumlah_qty ;$i++) { 
    if(!empty($qty[$i]) && !empty($id_cat[$i])) { 

插入預訂:

 $insert_booking_hd = $user_class->select($az); 
     $id_cates = $id_cat[$i]; 
     for($b = 0;$b<$qty[$i];$b++) { 

首先驗證是否$_POST[$id_cates)設置運行這段代碼:

  if(isset($_POST[$id_cates."".$b])){ 
       $id_seat = $_POST[$id_cates."".$b]; 

查找$ select_seat座位號找到座位,如果號碼是存在於$ seat_number:

   $select_seat = $user_class->select($query); 
       $seat_number = $user_class->select($querys); 
       $row_seat = $user_class->numrows($select_seat); 
       $row_seat2 = $user_class->numrows($seat_number); 
       if($row_seat>0) { 
        $update_seat = $user_class->update($update_false); 
        $bol[$b] = FALSE; 
       } else { 
        if($row_seat2>0) { 
         $insert_booking_dt = $user_class->insert($insert); 
         $update_seat = $user_class->update($update_true); 
         $bol[$b] = TRUE; 
        } else { 
         $bol[$b] = FALSE; 
        } 
       }  
      } else { 
       $insert_booking_dt = $user_class->insert($insert_without_seat); 
       $bol[$b] = TRUE; 
      } 

      if($bol[$b]) { 
       echo "FALSE"; 
       header("location:../../../print.php?id=$id_booking"); 
      } 
      else { 
       echo "WRONG"; 
       header("location:../../../event.php?msg=Same seat number"); 
      } 
     } 
    } 
} 

任何問題我的PHP驗證?

因爲如果我輸入的$id_seat陣列它將總是重定向到print.php雖然驗證是FALSE

例如,如果我輸入3數組,然後我回聲FALSE WRONG FALSE FALSE

仍然重定向到打印.php不是event.php

如何讀取一個數組是否得到錯誤,然後重定向到event.php?

回答

0

我怎樣才能讀取如果陣列的一個是拿錯,然後重定向到event.php?

您可能break出的for循環。

相反的:

else { 
    echo "WRONG"; 
    header("location:../../../event.php?msg=Same seat number"); 
} 

你可以嘗試:

else { 
    echo "WRONG"; 
    header("location:../../../event.php?msg=Same seat number"); 
    break 2; 
} 
+0

TY花花公子的工作:d – derylihs

+0

@derylihs歡迎您。順便說一下,在for循環之後使用'$ bol'嗎?如果是這樣,那麼我應該編輯我的答案。 – lifus

+0

不允許在循環中使用$ bol – derylihs