$ _post不包含任何内容

时间:2016-11-13 08:33:25

标签: php html mysql

我正在尝试登录,但似乎我的变量不包含anthing。 我之前遇到过这个问题,但我设法解决了,我的html表单中缺少name属性那个时间..但这次不知道我在哪里做错.plz帮助?

这是我的html片段。即使在我提交后它仍然是空白:

 <form action="onlogin.php" method="post">
                <h1>Login Form</h1>
                <div>
                    <input type="text" placeholder="Username" required="" name="username" />
                </div>
                <div>
                    <input type="password" placeholder="Password" required="" name="password" />
                </div>
                <div>
                    <input type="submit" value="Log in" />
                    <a href="#">Lost your password?</a>
                    <a href="signup.html">Register</a>
                </div>
            </form>

我的php片段是:

    <?php
      include ("config/config.php");//connects to db successfully
      if(isset($_POST["submit"]))
       {
       $username =  $_POST['username']; echo "$username";
       $password =  $_POST['password']; echo "$password";
       }
    ?>***

1 个答案:

答案 0 :(得分:2)

您在php脚本中检查$_POST["submit"]是否提交isset。但是你不能从你的表单中send

试试这个:

<form action="onlogin.php" method="post">
    <h1>Login Form</h1>
    <div>
        <input type="text" placeholder="Username" required="" name="username" />
    </div>
    <div>
        <input type="password" placeholder="Password" required="" name="password" />
    </div>
    <div>
        <input type="submit" name="submit" value="Log in" />
        <a href="#">Lost your password?</a>
        <a href="signup.html">Register</a>
    </div>
</form>