php登录系统无法正常工作

时间:2014-01-29 20:20:17

标签: php sql login

嗨,我有这段代码,但每当我输入任何用户名或密码时,无论是对还是错,它只会在else块中显示代码。我真的很感激任何帮助。

if (isset($_POST['email']) && isset($_POST['password']))
{
$username=htmlspecialchars($_POST['email']);
$username=trim($POST['email']);
$username=stripslashes($POST['email']);
$username=mysql_real_escape_string($POST['email']);
$password=htmlspecialchars($_POST['password']);
$password=trim($_POST['password']);
$password=stripslashes($_POST['password']);
$password=mysql_real_escape_string($_POST['password']);

}
mysql_select_db ($db,$dbconnect);
$check="SELECT * FROM students WHERE (username='$username') AND (password='$password')    
LIMIT 1";
$result=mysql_query($check);
$count=mysql_num_rows($result);


if ($count==1)
{
$_SESSION[$username];
$_SESSION[$password];
header ('Location: attendance.php');
exit ();

}
else
{
echo "wrong password or username";
}
?>

1 个答案:

答案 0 :(得分:0)

你应该使用mysqli或更好的PDO,因为mysql已被弃用但是试试这个。

if (isset($_POST['email']) && isset($_POST['password']))
{

    $username=mysql_real_escape_string($POST['email']);
    $password=mysql_real_escape_string($_POST['password']);

    mysql_select_db ($db,$dbconnect);
    $check="SELECT * FROM students WHERE (username='$username') AND (password='$password')    
    LIMIT 1";
    $result=mysql_query($check);
    $count=mysql_num_rows($result);

}


if (isset($count) && $count == 1)
{
    $_SESSION[$username];
    $_SESSION[$password];
    header ('Location: attendance.php');
    exit ();

}
else
{
    echo "wrong password or username";
}
?>