我有这样的代码
第一次循环计算有多少张数组:
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
仍然重定向到 print.php 而不是 event.php
如果数组之一出错,我如何读取然后重定向到 event.php?
最佳答案
block 引用>How can I read if one of array is get WRONG and then redirect to 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; }
关于php 从数组形式验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17896579/