I have this query to find out whether the email address the user typed in, already exists in the database.
if($res=mysql_query("SELECT address FROM email WHERE address ='{$new_emailaddress}'") <>FALSE) {
echo "This email address already exists . Enter a new one.";}
the problem is, the query always returns true. But I want to compare it to the email address the user enters.
Can anyone help me?
SQL query that is always true?
Moderator: General Moderators
Re: SQL query that is always true?
Because mysql_query always returns a resource id. Try this:
if($myRow = mysql_fetch_assoc(mysql_query("SELECT address FROM email WHERE address ='{$new_emailaddress}'") ))
if($myRow = mysql_fetch_assoc(mysql_query("SELECT address FROM email WHERE address ='{$new_emailaddress}'") ))
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: SQL query that is always true?
Code: Select all
$result = mysql_query("SELECT address FROM email WHERE address ='{$new_emailaddress}'");
if(mysql_num_rows($result) > 0) {
$myRow = mysql_fetch_assoc($result);
}(#10850)