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

  • Home
  • SEARCH
  • 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 8676433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:11:41+00:00 2026-06-12T20:11:41+00:00

I have this PHP function that gets the data of the currently logged in

  • 0

I have this PHP function that gets the data of the currently logged in user, or returns false if the visitor either isn’t logged in, or has invalid user_id and password_hash cookies. For some reason, $q->fetch() always returns FALSE.

if( $_COOKIE['cuid']!='' && $_COOKIE['cuph']!='' )
{
    try
    {
        $q = $db->prepare( 'SELECT * FROM users WHERE user_id = ? AND password = ?' );
        $data = array( $_COOKIE['cuid'], $_COOKIE['cuph'] ); // id and password hash
        $q->execute($data);
        $num = count( $q->fetchAll() ); // in my case, $num is set to 1
        if( $num == 1 )
        {
            $q->setFetchMode(PDO::FETCH_CLASS, 'User');
            $user = $q->fetch(); // $user is set to FALSE for some reason
            return $user;
        } else {
            return FALSE;
        }
    }
    catch( Exception $e )
    {
        $db->rollBack();
        echo 'Error: ' . $e->getMessage();
    }
} else {
    return FALSE;
}

Running that with exact data instead of placeholders in the query doesn’t change anything, and running that query directly in my database returns 1 row, like it should. I checked, $num does indeed equal 1. I don’t know why $q->fetch() returns FALSE, so any pointers would be very much appreciated.

  • 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-12T20:11:42+00:00Added an answer on June 12, 2026 at 8:11 pm

    You’re already fetching all results using fetchAll(). The result set is thereby exhausted, you cannot fetch any more results from it. You simply want $q->rowCount() to count the rows or save the array returned by fetchAll() somewhere and use it later.

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

Sidebar

Related Questions

I have this jQuery script: $(.show-div).data('loaded',false).click(function() { $.post(script.php, {id_1: var_id_1, id_2: var_id_2}, function(data){ $(this).data('loaded',true);
I have this Javascript function that sends username and password to php file through
this is function.php of a wordpress theme that NOD32 says this code have a
I have this jQuery code: $(document).ready(function() { $.ajax({ url: pages/+page+.php, cache: false }).done(function( html
I'm working in PHP. I have a function (F1) that gets called a variable
I currently have a grid with a grouping feature that gets data from a
i have this strange problem with the PHP function CTYPE_ALNUM if i do: PHP:
I have this part of code in my functions.php: function cc_admin_enqueue_scripts($hook) { $file_dir=get_bloginfo('template_directory'); wp_enqueue_script('media-upload');
I have this code: function submitTwice(f){ f.action = 'http://mydomain.com/threevideopage.php'; f.target='name'; f.submit(); } I left
I have this in my class When the second function is called php errors

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.