无法弄清楚为什么没有设置用户名和密码

时间:2017-02-09 15:57:44

标签: php

我正在制作一个带有嵌入式输入表格的导航栏,但登录按钮时没有设置用户名和密码的值。我陷入了困境,我无法弄清楚为什么会这样?

<div class="navbar-fixed">
<nav>
    <div class="nav-wrapper black darken-2 z-depth-4 navbar-fixed">
        <a href="#!" class="brand-logo">&nbsp&nbsp $~ CodersArena</a>
        <ul class="right hide-on-med-and-down " >

            <?php
            include('includes/bootstrap.php');
            $con = dbConnect();
            if (isset($_POST['username']) && isset($_POST['password'])){
                $username =$_POST['username'];
                $password = $_POST['password'];
                $sql = "SELECT username FROM users WHERE username='" . $username . "' AND password='" . $password . "'";

                $result = mysqli_query($con, $sql);


                if (mysqli_num_rows($result) > 0) {
                    echo"success";
                    $_SESSION['username'] = $username;
                    echo '<li>
                    <span class="white-text white">';
                    echo  $_SESSION['username'];
                    echo '</span>
                </li>';

                }
            }
            else
        {

            if (!isset($_SESSION['username'])) {

                echo '
            <form action="index.php"  method="POST" >
                <li style="padding: 20px auto; margin-right:10px ">
                    <input id="username" type="text" class="validate" style="height:30px" autocomplete="off" placeholder="Username">
                </li>&nbsp&nbsp&nbsp
                <li style="padding: 20px auto; margin-right:10px "> 
                    <input id="password" type="text" style="height:30px" autocomplete="off" placeholder="Password">
                </li>
                    <button style="padding: 20px auto; margin:10px " type="submit" class="btn-flat indigo darken-1 white-text right">Login</button>
            </form>';

            }
        }
            ?>

        </ul>

</nav>

1 个答案:

答案 0 :(得分:5)

您的<input>缺少name="username"name="password"属性,这些属性将进入POST请求。
任何没有name的输入都不会包含在表单提交中。