【发布时间】:2010-04-13 12:27:08
【问题描述】:
嘿,这是我的登录脚本,使用 PHP5 和 MYSQLi,我只是帮助我发现了查询中的错误,但它仍然不允许我登录,即使用户名和密码正确并且在数据库中,它只是保持返回错误:您的用户名和密码与我们的数据库中的任何内容都不匹配。但我知道他们会大声笑……有人能发现问题吗?
//Check if the form has been submitted
if (isset($_POST['login']))
{
//Check if username and password are empty
if ($_POST['username']!='' && $_POST['password']!='')
{
//Create query to check username and password to database
$validate_user = $mysqli->query('SELECT id, username, password, active FROM users WHERE = username = "'.$mysqli->real_escape_string($_POST['username']).'" AND password = "'.$mysqli->real_escape_string(md5($_POST['password'])).'"');
//We check if the query returns true
if ($validate_user->num_rows == 1)
{
$row = $validate_user->fetch_assoc();
//Check if the user has activated there account
if ($row['activated'] == 1)
{
$_SESSION['id'] = $row['id'];
$_SESSION['logged_in'] = true;
Header('Location: ../main/index.php');
}
//Show this error if activation returns as 0
else {
$error = '<p class="error">Please activate your account.</p>';
}
}
//Show this error if the details matched any in the db
else {
$error = '<p class="error">Your username and password are not in our database!</p>';
}
}
//Show this error if the username and password field have not been entered
else {
$error = '<p class="error">Please enter your username and password.</p>';
}
}
【问题讨论】:
-
密码字段中是否有 md5 哈希?
-
是的,要我给你看吗?
-
您是否有多个用户使用此用户名/密码组合?
-
不,我是数据库中唯一的用户,因为我正在开发 atm :(
-
您不会检查查询执行是否有错误。添加此代码 echo $mysqli->error;看看有没有