$dbh->query
适用于$queryUser = $dbh->query
,但不适用于$querySessions = $dbh->query
,$querySessions
为空,
echo $querySessions == null;
回声 1
进而
致命错误:在 /path/to/file.php 中的非对象上调用成员函数 fetchAll() 在线 (while(count($querySessions->fetchAll()) != 0))
if($_POST['loginbtn'])
{
$User = $_POST['user'];
$Pass = md5(md5("salt" . $_POST['pass'] . "salt2"));
if($User)
{
if($_POST['pass'])//not $Pass because thats hashed
{
$queryUser = $dbh->query("SELECT * FROM `Users` WHERE `UserName` = '" . base64_encode($User) . "' LIMIT 1");
$Record = $queryUser->fetch();
if($Pass != $Record["Password"])
{
echo "Incorect password.";
}
else
{
if($Record["Banned"] == 1)
{
echo "Sorry, your banned.";
}
else
{
if($Record["NeedsActivation"] == 1)
{
echo "You must activate your account before you can login.";
}
else
{
$SID = md5(rand(0,0x7fffffff) . "salt3");
$querySessions = $dbh->query("SELECT * FROM `Sessions` WHERE `ID` = " . $SID . " LIMIT 1");
echo $querySessions == null;
while(count($querySessions->fetchAll()) != 0)
{
$SID = md5(rand(0,0x7fffffff) . "salt2");
$querySessions = $dbh->query("SELECT * FROM `Sessions` WHERE `ID` = " . $SID . " LIMIT 1");
}
$_SESSION['id'] = $SID;
$dbh->query("INSERT INTO `godzchea_Site`.`Sessions` (`ID` ,`UserID`)VALUES ('" . $SID . "', '" . $Record["ID"] . "');");
echo base64_decode($Record["UserName"]) . " Logged in.";
}
}
}
}
else
{
echo "You must enter your password.";
}
}
else
{
echo "You must enter your username.";
}
}
你们中的任何人都可以看到为什么它被设置为null,以及是否有更好的循环方法,直到我得到一个空的id。