我正在处理留言板,我刚刚开始,现在正在处理登录功能。我有一个问题。每当我尝试获取数据时,它要么什么都不返回,要么返回一个“1”。鉴于我是将 mySQL 与 PHP 集成的新手,我不知道发生了什么。如果你能帮助我弄清楚我做错了什么,那就太好了。
$query = mysql_query("
SELECT * FROM users WHERE username='$username'
");
while ($row = mysql_fetch_assoc($query)){
$dbID = $row['id'];
$dbUser = $row['username'];
$dbPass = $row['password'];
}
if ($dbUser = $username && $dbPass = $password) {
//if user and pass match do stuff
$_SESSION['username'] = $dbUser;
$_SESSION['id'] = $dbID;
$_SESSION['ip'] = $_SERVER['HTTP_USER_AGENT'];
header("Location: messageboard.php");
}
else {
//if user and pass dont match do stuff
$_SESSION['loginError'] = "Your username and password do not match";
header("Location: login.php");
}
所有代码返回 - ID:用户名:1 IP:Mozilla/5.0(Windows NT 6.2;WOW64)AppleWebKit/537.36(KHTML,如 Gecko)Chrome/28.0.1500.95 Safari/537.36