简体   繁体   中英

User login not working unknown error

i don't know what's wrong with my login script. It keeps saying invalid username or password. But in my eyes, everything is set as it should be.

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 Form:

<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>

I'm trying for hours and hours to fix it, but i can't. You all are my last hope. Thanks in advance!

You appear to have these two lines in the wrong order:

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

Later code will be using $username which won't have been initialised properly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM