No trust me you're on the right track.  You don't need the double ==
operator in the SQL query.  Try something like this...

$query = "SELECT * FROM membersWHERE username = '$username'";
$result = mysql_query($query, $db);
if (mysql_num_rows($result) == 0)
    echo "The username <i>$username</u> does not exist.";

To check for blank fields simply ask "... WHERE username = ''".


----- Original Message -----
From: "Tyler Durdin" <[EMAIL PROTECTED]>
Sent: Monday, July 29, 2002 12:46 PM
Subject: [PHP] comparing a variable to value in DB

> I have a column in my DB named username and i am trying to compare a
> ID called $username to the field in my DB called username. The way i had
> done it before was SELECT * from tablename WHERE Tablename.username ==
> $username, but this does not seem to be working is there a better way to
> this? Also, I would like to know how to tell if a field is blank. For
> example, if  my SELECT statement comes back and there is no data in the
> username column how can i check for this?
> _________________________________________________________________
> Send and receive Hotmail on your mobile device:
> --
> PHP General Mailing List (
> To unsubscribe, visit:

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to