Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用表单输入验证查询记录_Php_Mysqli_Location - Fatal编程技术网

Php 如何使用表单输入验证查询记录

Php 如何使用表单输入验证查询记录,php,mysqli,location,Php,Mysqli,Location,在我下面的代码中,我有两个表单部分,第一个是从数据库获取信息,第二个是验证数据库中的记录,我的问题是如何验证记录并重定向到错误页,或者如果输入表单没有任何记录,则重定向到索引页,这是我的代码 <?php include_once 'init.php'; $error = false; //check if form is submitted if (isset($_POST['book'])) { $book = mysqli_real_escape_string($conn,

在我下面的代码中,我有两个表单部分,第一个是从数据库获取信息,第二个是验证数据库中的记录,我的问题是如何验证记录并重定向到错误页,或者如果输入表单没有任何记录,则重定向到索引页,这是我的代码

<?php
include_once 'init.php';
$error = false;

//check if form is submitted
if (isset($_POST['book'])) {
    $book = mysqli_real_escape_string($conn, $_POST['book']);
    $action = mysqli_real_escape_string($conn, $_POST['action']);
    if (strlen($book) < 6) {
        $error = true;
        $book_error = "booking code must be alist 6 in digit";
    }
    if (!is_numeric($book)) {
        $error = true;
        $book_error = "Incorrect booking code";
    }
    if (empty($_POST["action"])) {
        $error = true;
        $action_error = "pick your action and try again";
    }
    if (!$error) {
        if(preg_match('/(check)/i', $action)) {
            echo "6mameja";
        } 
        if (preg_match('/(comfirm)/i', $action)) {
            if(isset($_SESSION["user_name"]) && (trim($_SESSION["user_name"]) != "")) {
                $username=$_SESSION["user_name"];
                $result=mysqli_query($conn,"select * from users where username='$username'");
            }
            if ($row = mysqli_fetch_array($result)) {
                $id = $row["id"];
                $username=$row["username"];
                $idd = $row["id"];
                $username = $row["username"];
                $ip = $row["ip"];
                $ban = $row["validated"];
                $balance = $row["balance"];
                $sql = "SELECT `item_name` , `quantity` FROM `books` WHERE `book`='$book'";
                $query = mysqli_query($conn, $sql);
                while ($rows = mysqli_fetch_assoc($query)) {
                    $da  = $rows["item_name"]; $qty  = $rows["quantity"];
                    $sqll = mysqli_query($conn, "SELECT * FROM promo WHERE code='$da' LIMIT 1");
                   while ($prow = mysqli_fetch_array($sqll)) {
                       $pid = $prow["id"];
                       $price = $prow["price"];
                       $count = 0;
                       $count = $qty * $price;
                       $show = $count + $show;
                    }
                }
                echo "$show";
                echo "$balance";
                if ($show<$balance) {
                    if (isset($_POST["verify"])) {
                        $pass = mysqli_real_escape_string($conn, $_POST["pass"]);
                        if ($pass != "$username") {
                            header("location: index.php");
                        }
                        elseif ($pass = "$username") {
                            header("location: ../error.php");
                        }
                    }
                    echo '<form action="#" method="post" name="verify"><input class="text" name="pass" type="password" size="25" /><input class="text" type="submit" name="verify" value="view"></form>';
                    echo "you cant buy here";
                    exit();
                }
            } else {
                $errormsg = "Error in registering...Please try again later!";
            }
        }
    }
}
?>

<form role="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="booking">
    <fieldset>
        <legend>Check Booking</legend>

        <div class="form-group">
            <label for="name">Username</label>
            <input type="text" name="book" placeholder="Enter  Username" required value="<?php if($error) echo $book; ?>" class="form-control" />
            <span class="text-danger"><?php if (isset($book_error)) echo $book_error; ?></span>
        </div>
        <input type="submit" name="booking" value="Sign Up" class="btn btn-primary" />
        <table>
            <input type="radio" name="action" value="comfirm" <?php if(isset($_POST['action']) && $_POST['action']=="comfirm") { ?>checked<?php  } ?>> 
            <input type="radio" name="action" value="check" <?php if(isset($_POST['action']) && $_POST['action']=="check") { ?>checked<?php  } ?>> Check booking <span class="text-danger"><?php if (isset($action_error)) echo $action_error; ?></span>
            </div>
        </table>
    </fieldset>
</form>