tags:

views:

29

answers:

1

I need help finishing this statement. It is frustrating that two of the PHP phone books here gloss over PDO's almost all together.

All I need to do is check the database for a username that is already taken.

Here is the start of the statement.

$sql = " SELECT * FROM users WHERE userid = '$userid'";
$result = $dbh->query($sql);

What parts do I need to add to write my 'if' statement?

A: 

Something like this:

$sql = " SELECT * FROM users WHERE userid = '$userid'";
$result = $dbh->query($sql);
$row = $result->fetch();

if ($row)
    echo 'Userid is taken';

I'm not sure about your question because you're asking about username but selecting userid... did you mean to select on username?

Greg
Shouldn't it be if($row) ?
tomp
I should have used the word userid instead of username. I was thinking about describing the problem not realizing that I will be talking to programmers. :)
Oops yeah that's what I meant - thanks
Greg
Ha! I thought it was wrong the first time until I realized that I put a colon at the end of line.... Such a n00b! Can't wait until this stuff flows easier. Any good books on PDO?