我有2个错误,但其中只有一个正在工作

时间:2019-05-09 17:54:53

标签: php

无论我输入什么,都会收到相同的错误“所有字段均为必填”,但仅当字段为空时才会出现此错误。 输入错误的详细信息时,我应该出现其他错误,但我只会遇到第一个错误。 我是一个初学者,我花了一个小时查看我的代码,但我仍然不能自己解决它:/

<?php
session_start();

include_once('../includes/connection.php');

if (isset($_SESSION['logged_in'])){
    //display index
} else {
    if (isset($_POST['username'], $_POST['password'])){
        $username = $_POST['username'];
        $password = $_POST['password'];

        if (empty($username) or ($password)) {
            $error = 'All fileds are required';
        }else {
            $query = $pdo->prepare("SELECT * FROM user WHERE user_name = ? AND user_password = ? ");

            $query->bindValue(1, $username);
            $query->bindValue(2, $password);

            $query->execute();

            $num = $query->rowCount();

            if ($num == 1) {

                //user entered correct details
            }else {
                // user enterde false details
                echo $error = 'Incorrect details!';
            }

        }
    }
    ?>

    <html>

    <head>
        <title>CMS Tuterial</title>
        <link rel="stylesheet" href="../assets/style.css" />

    </head>

    <body>
    <div class="container">
        <a href="index.php" id="logo">CMS</a>

        <br /><br />

        <?php if (isset($error)) { ?>
            <small style="color:#aa0000;"><?php echo $error; ?></small>
            <br /><br />
        <?php } ?>
        <form action="index.php" method="POST" autocomplete="off">

            <input type="text" name="username" placeholder="Username" />
            <input type="password" name="password" placeholder="Password" />
            <input type="submit" value="Login" />

        </form>

    </div>

    </body>

    </html>


    <?php
}


?>

0 个答案:

没有答案