用户登录不工作未知错误

时间:2014-06-30 04:11:09

标签: php html mysql session login

我不知道我的登录脚本有什么问题。它一直说无效的用户名或密码。但在我看来,一切都按照应有的方式设定。

PHP5:

<?php require ('../lib/config.php'); ?>
<?php

ob_start();
$tbl_name='users';
$user_name='Username';
$pass_name='Password';
$salt='';

mysql_connect("$cchost", "$ccuser", "$ccpass")or die("cannot connect"); 
mysql_select_db("$ccname")or die("cannot select DB");

$username=str_replace(' ','_', $myusername); 
$myusername=$_POST['username']; 
$mypassword=$_POST['password'];
$password=hash('whirlpool', $mypassword);

$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM $tbl_name WHERE $user_name='$username' and $pass_name='$password'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$donator=$row['donator'];
$player=$row['player'];
$count=mysql_num_rows($result);

if ($donator == '1') {
session_register("donator"); 
}
if ($player == '1') {
session_register("player"); 
}
if($count==1){
session_register("username");
header("Location: index_ucp.php");
}
else {
header("Location: login_ucp.php?err=1");
}
ob_end_flush();
?>

HTML表格:

<div class="login">
      <form method="post" name="frmLogin" class="well form-inline" action="dologin.php">
        <input name="username" type="text" class="input-medium" placeholder="Username">
        <input name="password" type="password" class="input-medium" placeholder="Password">
        <button name="btnLogin" type="submit" class="btn">Sign in</button>
      </form>
</div>

我正在尝试数小时和数小时来解决它,但我不能。你们都是我最后的希望。 提前谢谢!

1 个答案:

答案 0 :(得分:2)

您似乎有这两行的顺序错误:

$username=str_replace(' ','_', $myusername); 
$myusername=$_POST['username']; 

以后的代码将使用$username,但未能正确初始化