php 从数组形式验证

标签 php mysql arrays

我有这样的代码

第一次循环计算有多少张数组:

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?

最佳答案

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/

相关文章:

php - 导入 LOAD DATA INFILE 时将我的 php 变量连接到 csv 数据

mysql - 当我尝试使用 MySQL ODBC 驱动程序时,什么可能导致 MS Query (msqry32.exe) 崩溃?

java - 我的数组在哪里发生了变化?

java - 双数组对单数组的运算

php - 高优先级齿轮工作业未被视为高优先级

php - 我对 php ://input function? 做错了什么

php - Laravel - 防止对空输入进行验证检查

mysql - 在表中输入整条记录会自动更新其他表中的相应字段

mysql - SQL查询选择语句

c - C中使用指针对数组进行升序排序