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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:22:13+00:00 2026-06-01T23:22:13+00:00

I have just one text field where a user can enter there username or

  • 0

I have just one text field where a user can enter there username or email address to reset there password.

First here is the code: (I only included code that I know where problem resides).

try {

    // connect to database
    $dbh = sql_con();

    // prepare query
    $stmt = $dbh->prepare("
                     SELECT COUNT(*)
                     FROM
                         users
                     WHERE
                         user_login = :username
                     OR
                         user_email = :email
                     ");

    // execute query
    $stmt->execute(array(':username' => $username_email, ':email' => $username_email));

    if ($stmt->fetchAll() > 0) {

        // something was found
        // just echoing at the moment until i figure out what i am doing wrong
        echo 'i found something';
        exit;

    } else {
        // nothing found
        echo 'i found nothing';
        exit;
    }

}
catch (PDOException $e) {

    ExceptionErrorHandler($e);
    require_once($footer_inc);
    exit;
}

Not sure what I am doing wrong, probably something very silly, but when I enter a username or email address that I know is not in the database it still echoes out I found something.

What I am doing wrong?

I was going to use rowCount but as suggested by the PHP manual it states:

PDOStatement::rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object.
If the last SQL statement executed by the associated PDOStatement was a SELECT.
statement, some databases may return the number of rows returned by that statement.
However, this behaviour is not guaranteed for all databases and should not be relied on for portable applications.

So basically the PHP manual is saying I should do a Count(*) before performing my real query then work with the result.

  • 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-01T23:22:14+00:00Added an answer on June 1, 2026 at 11:22 pm

    Do you maybe mean if (count($stmt->fetchAll()) > 0) {

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

Sidebar

Related Questions

I have two div's one has textbox in it and other just plain text.
In one of my first Cocoa applications I have just a single window with
I'm trying to verify the existence of username in DB. I have one field
i am building one module wherein user can post their data. i have few
In my iPhone app I have a settings page where a user can enter
I have just one cs file in my repository which Git seems to think
With my database upgrade scripts, I typically just have one long script that makes
To localitie items in the standard directories, I have just used either one of
I have just updated to Snow Leopard and one of my important Flash files
I have just re-written the authentication for one of our internal web applications to

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.