2016-11-13 44 views
-2

我想登录,但似乎我的变量不包含anthing。 我以前遇到过这个问题,但我设法解决这个问题,名称属性在我的HTML表单中缺少时间..但这次不知道我在哪里做错了.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"; 
     } 
    ?>*** 
+0

你没有$ _ POST [ '提交'],你可以检查,如果(isset($ _ POST [ '用户名'])),而不是 –

+0

thankuu这么多... 。现在它工作正常.. – Rani

回答

2

您检查$_POST["submit"]提交isset或不PHP脚本。但你不需要从你的表格中获得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> 
+1

使用isset来检查提交是否被设置是不好的做法。我会建议使用if($ _SERVER ['REQUEST_METHOD'] ==“POST”) – 2016-11-13 08:47:12