繁体   English   中英

从数组形式的PHP验证

[英]php validation from array form

我有这样的代码

第一次循环计数数组中有多少个:

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数组,尽管验证为FALSE,它将始终重定向到print.php

例如,如果我输入3数组,然后回显FALSE WRONG FALSE FALSE

仍然重定向到print.php而不是event.php

我如何读取数组之一是否被错误然后重定向到event.php?

我怎样才能读取如果阵列中的一个是拿错,然后重定向到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;
} 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM