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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:11:19+00:00 2026-06-01T19:11:19+00:00

I have a users table and a users_banlist table. On my registration form i

  • 0

I have a users table and a users_banlist table.

On my registration form i want to check all in one query whether the username someone entered on form exists in the users table and see if it also exists on the users_banlist table.

I can do them on there own in individual queries but would rather do it all in one.

Here is what I got, but even though I enter a username that is taken it does not tell me it’s already taken.

$stmt = $dbh->prepare("
SELECT
  users.user_login,
  users_banlist.user_banlist
FROM
  users ,
  users_banlist
WHERE
  users.user_login = ? OR
  users_banlist.user_banlist = ?");

// checker if username exists in users table or users_banlist table
$stmt->execute(array($username, $username));

if ( $stmt->rowCount() > 0 ) {
    $error[] = 'Username already taken';
}

Basically I think it is something to do with the execute or rowCount(), could anyone tell me where I am going wrong? Being new to pdo I’m finding it a little confusing at the moment.

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

    You could use the query

    SELECT
      users.user_login
    FROM
     users 
    WHERE
      users.user_login = ? 
    UNION ALL
    SELECT
      users_banlist.user_banlist
    FROM
      users_banlist
    WHERE
      users_banlist.user_banlist = ?
    

    and then proceed as normal. What you were using is a CROSS JOIN which returns the cartesian product that produce rows which combine each row from the first table with each row from the second table. If one of those tables returns 0 rows you get 0 results

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

Sidebar

Related Questions

I have users table. There are three other tables: developers, managers, testers. All of
i have users table and i have posts table i want select from users
I have a users table and a friends table. I want to get the
I'm using Sql-Server 2005 I have Users table with userID and gender. I want
I have a users table with name and surname and a search form with
I have a users table in a database, where the user enters a form
I have a basic users table I want to create in MySQL. I do
I have a users table, and a roles table. I want to make a
I have a users table, the user ID is public. But I want to
I'm looking for a schema-independent query. That is, if I have a users table

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.