Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.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在query()命令之前被切断。帮助:)_Php_Html_Mysql - Fatal编程技术网

PHP在query()命令之前被切断。帮助:)

PHP在query()命令之前被切断。帮助:),php,html,mysql,Php,Html,Mysql,我正在制作一个测试loginform,并使用一个本地托管的mysql数据库。我正试图使用一个名为pageid的id将整个loginform保存在一个文件中。每个pageid都有自己的html页面,我的所有内容都在一个echo中。但就在质询之前。。。;命令时,脚本停止用PHP编写,并将其作为普通文本输入。这是为什么?有人能帮我解决吗。如果有什么办法可以更聪明地做到这一点,我愿意听取建议。下面是完整的代码。提前感谢: <?php $connection = new mysqli("lo

我正在制作一个测试loginform,并使用一个本地托管的mysql数据库。我正试图使用一个名为pageid的id将整个loginform保存在一个文件中。每个pageid都有自己的html页面,我的所有内容都在一个echo中。但就在质询之前。。。;命令时,脚本停止用PHP编写,并将其作为普通文本输入。这是为什么?有人能帮我解决吗。如果有什么办法可以更聪明地做到这一点,我愿意听取建议。下面是完整的代码。提前感谢:

<?php
    $connection = new mysqli("localhost", "root", "usbw", "loginform");

    if(!isset($_GET["pageid"])) {
        header("Location: index.php?pageid=1");
        die();
    } elseif($_GET["pageid"] == 1) {
        echo '
            <html>
                <head>
                    <style type="text/css">
                        html, body {
                            height: 100%;
                        }

                        html {
                            display: table;
                            margin: auto;
                        }

                        body {
                            background-color: rgb(208, 128, 0);
                            display: table-cell;
                            vertical-align: middle;
                        }

                        #username, #password {
                            width: 300px;
                            height: 25px;
                            font-size: 25px;
                            border-color: black;
                        }

                        #login, #register {
                            font-size: 25px;
                            background: transparent;
                            border-color: black;
                        }

                        #register {
                            margin-left: 114px;
                        }
                    </style>
                </head>
                <body>
                    <form method="post" action="index.php?pageid=7">
                        <input type="text" id="username" placeholder="Username"><br><br>
                        <input type="password" id="password" placeholder="Password"><br><br>
                        <input type="submit" id="login" value="Login">
                        <input type="button" id="register" value="Register" onclick="window.location = \'index.php?pageid=2\';">
                    </form>

                    <?php
                        if(isset($_POST["username"]) & isset($_POST["password"])) {
                            $usernameHash = hash("sha512", $_POST["username"]);
                            $passwordHash = hash("sha512", $_POST["password"]);

                            $request = "SELECT * FROM users";
                            $result = $connection -> query($request);
                            while($user = $result -> fetch_assoc()) {
                                if($user["username"] == $usernameHash) {
                                    if($user["password"] == $passwordHash) {
                                        header("Location: index.php?pageid=3&userid=" . $user["id"]);
                                        die();
                                    } else {
                                        header("Location: index.php?pageid=4");
                                        die();
                                    }
                                } else {
                                    header("Location: index.php?pageid=4");
                                    die();
                                }
                            }
                        } else {
                            echo "not ok";
                        }
                    ?>
                </body>
            </html>
        ';
    } elseif($_GET["pageid"] == 2) {
        echo '
            <html>
                <head>
                    <style type="text/css">
                        html, body {
                            height: 100%;
                        }

                        html {
                            display: table;
                            margin: auto;
                        }

                        body {
                            background-color: rgb(208, 128, 0);
                            display: table-cell;
                            vertical-align: middle;
                        }

                        #usernameReg, #passwordReg, #passwordConfirm, #firstName, #lastName, #email, #phoneNr {
                            width: 300px;
                            height: 25px;
                            font-size: 25px;
                            border-color: black;
                        }

                        #firstName, #lastName {
                            width: 233px;
                        }

                        #email {
                            width: 400px;
                        }

                        #phoneNr {
                            width: 200px;
                        }

                        #register {
                            font-size: 25px;
                            background: transparent;
                            border-color: black;
                        }
                    </style>
                </head>
                <body>
                    <form method="post" action="index.php?pageid=8">
                        <input type="text" id="usernameReg" placeholder="New username"><br><br>
                        <input type="password" id="passwordReg" placeholder="New password"><br><br>
                        <input type="password" id="passwordConfirm" placeholder="Confirm password"><br><br><br>
                        <input type="text" id="firstName" placeholder="First name"><br><br>
                        <input type="text" id="lastName" placeholder="Last name"><br><br><br>
                        <input type="text" id="email" placeholder="New email"><br><br>
                        <input type="text" id="phoneNr" placeholder="Phone number"><br><br>
                        <input type="submit" id="register" value="Register">
                    </form>

                    <?php
                        if(isset($_POST["usernameReg"]) & isset($_POST["passwordReg"]) & isset($_POST["passwordConfirm"]) & isset($_POST["firstName"]) & isset($_POST["lastName"]) & isset($_POST["email"]) & isset($_POST["phoneNr"])) {
                            if($_POST["passwordReg"] != $_POST["passwordConfirm"]) {
                                header("Location: index.php?pageid=6");
                                die();
                            }

                            $usernameHash = hash("sha512", $_POST["usernameReg"]);
                            $passwordHash = hash("sha512", $_POST["passwordReg"]);
                            $firstNameHash = hash("sha512", $_POST["firstName"]);
                            $lastNameHash = hash("sha512", $_POST["lastName"]);
                            $emailHash = hash("sha512", $_POST["email"]);
                            $phoneNrHash = hash("sha512", $_POST["phoneNr"]);

                            $request = "SELECT * FROM users";
                            $result = $connection -> query($request);
                            while($user = $result -> fetch_assoc()) {
                                if($user["username"] != $usernameHash) {
                                    if($user["email"] != $emailHash) {
                                        if($user["phoneNr"] != $phoneNrHash) {
                                            $request = "INSERT INTO users (`username`, `password`, `firstName`, `lastName`, `email`, `phoneNr`) VALUES (\'" . $usernameHash . "\', \'" . $passwordHash . "\', \'" . $firstNameHash . "\', \'" . $lastNameHash . "\', \'" . $emailHash . "\', \'" . $phoneNrHash . "\')";
                                            $result = $connection -> query($request);

                                            header("Location: index.php?pageid=5");
                                            die();
                                        } else {
                                            header("Location: index.php?pageid=6");
                                            die();
                                        }
                                    } else {
                                        header("Location: index.php?pageid=6");
                                        die();
                                    }
                                } else {
                                    header("Location: index.php?pageid=6");
                                    die();
                                } 
                            }
                        } else {
                            echo "not ok";
                        }
                    ?>
                </body>
            </html>
        ';
    } elseif($_GET["pageid"] == 3) {

    } elseif($_GET["pageid"] == 4) {

    } elseif($_GET["pageid"] == 5) {

    } elseif($_GET["pageid"] == 6) {

    }
?>

虽然这不是打印html页面的正确方法,但可以用下面的方法来代替

<?php
    $connection = new mysqli("localhost", "root", "usbw", "loginform");

    if(!isset($_GET["pageid"])) {
        header("Location: index.php?pageid=1");
        die();
    } elseif($_GET["pageid"] == 1) {
        echo '
            <html>
                <head>
                    <style type="text/css">
                        html, body {
                            height: 100%;
                        }

                        html {
                            display: table;
                            margin: auto;
                        }

                        body {
                            background-color: rgb(208, 128, 0);
                            display: table-cell;
                            vertical-align: middle;
                        }

                        #username, #password {
                            width: 300px;
                            height: 25px;
                            font-size: 25px;
                            border-color: black;
                        }

                        #login, #register {
                            font-size: 25px;
                            background: transparent;
                            border-color: black;
                        }

                        #register {
                            margin-left: 114px;
                        }
                    </style>
                </head>
                <body>
                    <form method="post" action="index.php?pageid=7">
                        <input type="text" id="username" placeholder="Username"><br><br>
                        <input type="password" id="password" placeholder="Password"><br><br>
                        <input type="submit" id="login" value="Login">
                        <input type="button" id="register" value="Register" onclick="window.location = \'index.php?pageid=2\';">
                    </form>

                    <?php
                        if(isset($_POST["username"]) & isset($_POST["password"])) {
                            $usernameHash = hash("sha512", $_POST["username"]);
                            $passwordHash = hash("sha512", $_POST["password"]);

                            $request = "SELECT * FROM users";
                            $result = $connection -> query($request);
                            while($user = $result -> fetch_assoc()) {
                                if($user["username"] == $usernameHash) {
                                    if($user["password"] == $passwordHash) {
                                        header("Location: index.php?pageid=3&userid=" . $user["id"]);
                                        die();
                                    } else {
                                        header("Location: index.php?pageid=4");
                                        die();
                                    }
                                } else {
                                    header("Location: index.php?pageid=4");
                                    die();
                                }
                            }
                        } else {
                            echo "not ok";
                        }
                    ?>
                </body>
            </html>
        ';
    } elseif($_GET["pageid"] == 2) {
        echo '
            <html>
                <head>
                    <style type="text/css">
                        html, body {
                            height: 100%;
                        }

                        html {
                            display: table;
                            margin: auto;
                        }

                        body {
                            background-color: rgb(208, 128, 0);
                            display: table-cell;
                            vertical-align: middle;
                        }

                        #usernameReg, #passwordReg, #passwordConfirm, #firstName, #lastName, #email, #phoneNr {
                            width: 300px;
                            height: 25px;
                            font-size: 25px;
                            border-color: black;
                        }

                        #firstName, #lastName {
                            width: 233px;
                        }

                        #email {
                            width: 400px;
                        }

                        #phoneNr {
                            width: 200px;
                        }

                        #register {
                            font-size: 25px;
                            background: transparent;
                            border-color: black;
                        }
                    </style>
                </head>
                <body>
                    <form method="post" action="index.php?pageid=8">
                        <input type="text" id="usernameReg" placeholder="New username"><br><br>
                        <input type="password" id="passwordReg" placeholder="New password"><br><br>
                        <input type="password" id="passwordConfirm" placeholder="Confirm password"><br><br><br>
                        <input type="text" id="firstName" placeholder="First name"><br><br>
                        <input type="text" id="lastName" placeholder="Last name"><br><br><br>
                        <input type="text" id="email" placeholder="New email"><br><br>
                        <input type="text" id="phoneNr" placeholder="Phone number"><br><br>
                        <input type="submit" id="register" value="Register">
                    </form>


                </body>
            </html>
        ';

                        if(isset($_POST["usernameReg"]) & isset($_POST["passwordReg"]) & isset($_POST["passwordConfirm"]) & isset($_POST["firstName"]) & isset($_POST["lastName"]) & isset($_POST["email"]) & isset($_POST["phoneNr"])) {
                            if($_POST["passwordReg"] != $_POST["passwordConfirm"]) {
                                header("Location: index.php?pageid=6");
                                die();
                            }

                            $usernameHash = hash("sha512", $_POST["usernameReg"]);
                            $passwordHash = hash("sha512", $_POST["passwordReg"]);
                            $firstNameHash = hash("sha512", $_POST["firstName"]);
                            $lastNameHash = hash("sha512", $_POST["lastName"]);
                            $emailHash = hash("sha512", $_POST["email"]);
                            $phoneNrHash = hash("sha512", $_POST["phoneNr"]);

                            $request = "SELECT * FROM users";
                            $result = $connection -> query($request);
                            while($user = $result -> fetch_assoc()) {
                                if($user["username"] != $usernameHash) {
                                    if($user["email"] != $emailHash) {
                                        if($user["phoneNr"] != $phoneNrHash) {
                                            $request = "INSERT INTO users (`username`, `password`, `firstName`, `lastName`, `email`, `phoneNr`) VALUES (\'" . $usernameHash . "\', \'" . $passwordHash . "\', \'" . $firstNameHash . "\', \'" . $lastNameHash . "\', \'" . $emailHash . "\', \'" . $phoneNrHash . "\')";
                                            $result = $connection -> query($request);

                                            header("Location: index.php?pageid=5");
                                            die();
                                        } else {
                                            header("Location: index.php?pageid=6");
                                            die();
                                        }
                                    } else {
                                        header("Location: index.php?pageid=6");
                                        die();
                                    }
                                } else {
                                    header("Location: index.php?pageid=6");
                                    die();
                                } 
                            }
                        } else {
                            echo "not ok";
                        }

    } elseif($_GET["pageid"] == 3) {

    } elseif($_GET["pageid"] == 4) {

    } elseif($_GET["pageid"] == 5) {

    } elseif($_GET["pageid"] == 6) {

    }
?>

你已经把你的目标放在了这不是你想做的事情上。尽可能将代码与HTML分开。您应该最终得到一个HTML文件,其中偶尔会出现一些错误。除了循环和条件之外,没有逻辑。