登录表单不进行身份验证

时间:2013-01-11 15:11:21

标签: php html forms

我已经为我的网站创建了一个登录表单,但是目前它没有用,我被定向到invalid.php,这表明我的身份验证失败了。

 <?php
     session_start();
     include("scripts/dbconnect.php");
     $numrows=0;
     $password=$_POST['password'];
     $email=$_POST['email'];
     $query="select fname,lname,email from mayan_users where (password='$password' && email='$email')";
     $link = mysql_query($query);
     if (!$link) {
      die('login error');
     }
     $numrows=mysql_num_rows($link);
     if ($numrows>0){  // authentication is successfull
      $row = mysql_fetch_array($link, MYSQL_ASSOC);
      $_SESSION['user']['fname']=$row['fname'];
      $_SESSION['user']['lname']=$row['lname'];
      $_SESSION['user']['email']=$row['email'];
      header("location:../index2.php");
     } else {
      header("location:../invalid.php");  // authentication was unsuccessfull
     }
    ?>

这是我的登录表单

<div id="Loginform" style="background-color:fuchsia; width:100%">

<span id="logspan">
     <input type="email" name="email" id="email" placeholder="Email" required />
     <input type="password" name="password" id="password" placeholder="Password" required/>
     <input type="button" name="submit" style="cursor:pointer" id="submit" value="Log In" onclick="logMeIn()" />
    </span>

</div>

4 个答案:

答案 0 :(得分:4)

如果您未通过其他方式提交,则可能需要将您的登录信息包装在表单标记中。

<form method="post" action="">
     <span id="logspan">
         <input type="email" name="email" id="email" placeholder="Email" required />
         <input type="password" name="password" id="password" placeholder="Password" required/>
         <input type="button" name="submit" style="cursor:pointer" id="submit" value="Log In" onclick="logMeIn()" />
     </span>
</form>

如果您的PHP在另一个文档中,则将操作设置为表单处理器

action="form-processor.php"

(谢谢你!)

答案 1 :(得分:1)

你没有表格标签。像这样添加它们

<form method="POST" action="">
<!-- INSERT INPUTS HERE -->
</form>

答案 2 :(得分:0)

试试这个:

<form id="Loginform" style="background-color:fuchsia; width:100%">

<span id="logspan">
     <input type="email" name="email" id="email" placeholder="Email" required />
     <input type="password" name="password" id="password" placeholder="Password" required/>
     <input type="button" name="submit" style="cursor:pointer" id="submit" value="Log In" onclick="logMeIn()" />
    </span>

</form>

答案 3 :(得分:0)

首先,如果您的PHP版本支持,我建议您使用PDO 然后我想你的javascript函数以正确的方式发送参数 最后,您可以避免检查行数。简单地

if($row = mysql_fetch_array($link))
{
  ...
}
else
{
  header("location: ../invalid.php");
  exit; //It's a good practice
}