$dbh->query works on $queryUser = $dbh->query, but not on $querySessions = $dbh->query, $querySessions is null,
echo $querySessions == null; echos 1
and then
Fatal error: Call to a member function fetchAll() on a non-object in
/path/to/file.php on line (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.";
}
}
can any of you see why its being set to null,
and if there’s a better way to loop till I get a empty id.
The problem stand in the fact that that query, the one associated to
$querySessionis being a failure. Probably there’s an error in your query because what the Manual say is:I’m not sure, but it also could be that no rows has been found.
A suggestion I could give to you, to find out what’s the real errors is:
try{/*code in here*/}catch(PDOException $e){ exit($e->getMessage()); }and see what it output.$SIDand try to run it into phpmyadmin, directly into the database.Note that the fatal error is also related to the fact that your query is returning false instead of an object. That errors just say that you are treating
$querySessionas an object but it is not.For more information just leave a comment and I’ll answer.
Good luck.