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 8178133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:41:25+00:00 2026-06-06T23:41:25+00:00

I am trying to match a username in the database. If the username match

  • 0

I am trying to match a username in the database. If the username match it returns true otherwise it returns false.

At the moment it will always return false even when the username is correct.

Here is the class and call I’m using:

class register{
  private $result;

  public function __construct($post_data, PDO $dbh){

    $this->post_data = array_map('trim', $post_data);
    $this->dbh = $dbh;

  }

  public function checkUsername(){
    $stmt = $this->dbh->prepare("COUNT(*) FROM oopforum_users WHERE username = ?");
    $stmt->bindParam(1, $this->post_data['reg_username'], PDO::PARAM_STR);
    $stmt->execute();
    $this->result = $stmt->rowCount();
    if($this->result == 0){
        return false;
    }else{
        return true;
    }
  }

}


$register = new register($_POST, $dbh);
if($register->checkUsername()){
    //continue
}else{
    echo 'ERROR: That username is taken, please choose another one.';
}

Why is it returning false even though the username’s do match?

  • 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-06T23:41:27+00:00Added an answer on June 6, 2026 at 11:41 pm

    You forgot the SELECT statement:

    $stmt = $this->dbh->prepare("SELECT COUNT(*) FROM oopforum_users WHERE username = ?");
    

    Apart from that your query will always return a row (exactly 1 row), but the contents of that row could contain a 0 for the row count, so you need to change your logic: Either select a real column instead of COUNT(*) and use $stmt->rowCount() or read the value of the count and check for that.

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

Sidebar

Related Questions

I'm trying to match the username with a regex. Please don't suggest a split.
I am trying to match words driven from a database in a string input
I am trying to match the $username variable with the current session username (username
I'm trying to match usernames from a file. It's kind of like this: username=asd123
here is the case guys, I'm trying to check username on onblur event with
Im trying to match forum_id with several different forum_id's, something like forum_id = 5,7,12,43,63,78
I'm trying to match a string against a pattern, but there's one thing I
I'm trying to match the '12345' from a url in this form: http://domain.com/folder/title_of_this_12345 So
I'm trying to match expressions that start with PRE and end with PRE. I'm
I am trying to match on a string that begins with ./media I have

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.