Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7895477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:39:11+00:00 2026-06-03T07:39:11+00:00

$dbh->query works on $queryUser = $dbh->query , but not on $querySessions = $dbh->query ,

  • 0

$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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:39:12+00:00Added an answer on June 3, 2026 at 7:39 am

    The problem stand in the fact that that query, the one associated to $querySession is being a failure. Probably there’s an error in your query because what the Manual say is:

    PDO::query() returns a PDOStatement object, or FALSE on failure.
    

    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:

    1. You put all of your PDO code inside a try catch block like: try{/*code in here*/}catch(PDOException $e){ exit($e->getMessage()); } and see what it output.
    2. Take the query and the value of $SID and 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 $querySession as an object but it is not.

    For more information just leave a comment and I’ll answer.

    Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've come across a difficult to track bug, but I'm not sure what is
Having trouble with query results. The getSales() function works great the first time it
I have strange behaviour in Python/PyMongo. dbh = self.__connection__['test'] first = dbh['test_1'] second =
I have a generic function that closes connections and it takes a dbh, the
I connected Sqlite3 to my project to UITableview the code went fine But when
I'm trying to get the code below to work..... The error: ERRORSQLSTATE[42000]: Syntax error
I am trying to create a PDO class and I get the error: PHP
I'm trying to edit an INSERT query using bindParam(). Here is my code. public
I am learning OOPS concept and also using PDO , but really stuck in
I'm trying to query a MySQL databse using an array. $array=array('Group1','Group2','Group3'); $inQuery=implode(,,$array); //$inQuery='Group1'; //This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.