checking is username exists on two tables PHP PDO?

Posted by PHPLOVER on Stack Overflow See other posts from Stack Overflow or by PHPLOVER
Published on 2012-04-14T10:55:23Z Indexed on 2012/04/14 11:29 UTC
Read the original article Hit count: 144

Filed under:
|
|
|

Me again.

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 thou i enter a username that is taken it does not tell me its 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 im finding it a little confusing at the moment until i get my pdo book delivered to learn pdo.

Thank you as always, phplover

© Stack Overflow or respective owner

Related posts about php

Related posts about pdo