Home > Backend Development > PHP Tutorial > 用户登录有关问题 请大家帮帮忙

用户登录有关问题 请大家帮帮忙

WBOY
Release: 2016-06-13 12:54:00
Original
1076 people have browsed it

用户登录问题 请大家帮帮忙
$username = htmlspecialchars($_POST['username']);
$password = MD5($_POST['password']);

//包含数据库连接文件
include('conn.php');

//检测用户名及密码是否正确
$check_query = mysql_query("SELECT `uid` FROM `user` WHERE `username`='$username' AND `password`='$password' LIMIT 1");

if($result = mysql_fetch_array($check_query)){
    //登录成功
    $_SESSION['username'] = $username;
    echo "ok";
    exit;
} else {
    exit('登录失败!点击此处 返回 重试');
}
?>
请看看代码哪里出错了 明明数据库里存在输入的用户名的 但还是登录失败 
但是如果将`password`='$password'去掉 用户名是可以查询到的 但是密码随便输入什么都可以登录成功


------解决方案--------------------
<br />
	$result = mysql_query("SELECT uid FROM user WHERE username`='$username' AND `password`='$password'");<br />
	echo mysql_num_rows($result)."<br/>";//看一下这个结果是否为1,如果不是,则你的用户名或者密码有问题<br />
	if($mysql_num_rows($result)==1){<br />
		$row=mysql_fetch_array($result));<br />
		$_SESSION['username'] = $row['username'];<br />
		echo "登录成功";<br />
	}else{<br />
		echo "登录失败";<br />
	}<br />
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template