PHP登录返回错误的登录名,但用户名和密码正确[重复]

问题描述 投票:-1回答:1

我正在制作一个简单且非常基本的登录页面,以学习如何操作,但是尽管用户名和密码已正确记录在数据库中,但登录始终返回用户名和密码不正确。

我已经尽我所能解决该问题,包括在此处扫描其他类似问题,但没有发现任何帮助。我不确定是否只是忽略了一些非常简单的内容,只是需要一些新的眼神,还是我犯了一些重大错误/完全忘记了一些内容。

这里是checklogin.php

<?php session_start(); ?>
<?php include('db_access.php'); ?>


<?php
$myusername=$_POST['username'];
$mypassword=$_POST['password'];


$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);


$sql = "SELECT * FROM emp WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);


$count = mysql_num_rows($result);


if($count==1){

$_SESSION['in'] = 1;
$_SESSION['username']=$_POST['username'];
$_SESSION['password']=$_POST['password'];

}

header("location:../dashboard.php");
}

else {
    echo "Your username and password combination is incorrect. Hit the back button and try again.";
}
?>

如果需要,这里是表格:

    <form class="col s12" method="POST" action="includes/checklogin.php">
    <div class="row">
        <div class="input-field col s12">
          <input id="username" type="text">
          <label for="username">Username</label>
        </div>
      </div>
      <div class="row">
        <div class="input-field col s12">
          <input id="password" type="password">
          <label for="password">Password</label>
        </div>
      </div>
      <button class="btn waves-effect waves-light light-blue darken-1" type="submit" name="submit">login
    <i class="material-icons right">person_pin</i>
  </button>
  <div class="row">
    <p>No account? That's cool. <a href="register.php">Register here</a>!</p>
  </div>
    </form>
php mysql forms authentication session
1个回答
-1
投票

添加名称属性

<input name="username" id="username" type="text">
<input  name="password" id="password" type="password">
© www.soinside.com 2019 - 2024. All rights reserved.