开发者

PHP/MYSQL Duplicate Email Address

I am trying to prevent users on a site I'm working on from having duplicate email addresses. This is the method I'm using:

function createUser( $emlAd )
{
     $sql = "SELECT FROM Users WHERE email='$emlAd'" ;

     $result = mysql_query( $sql ) ;

     if( mysql_num_rows( $result ) > 0 )
     {
 die( "There is already a user with that email!" ) ;
     }//end开发者_如何学C if

     //rest of function
}//end createUser

This code does not accomplish its task, and the user is still able to create an account with an already used email. The weird thing is that when I change the if condition to:

mysql_num_rows( $result ) == 0 

The user isn't able to create an account with any email address. Why does the code not pass control to the if block when the number of rows is greater than 0?


Try this:

SELECT * FROM... (note the asterisk after SELECT).. I don't think you are calling any records (except the 1st record in Users) by the way you are running it. I could be wrong but give it a shot anyhow,.


it looks like you're never getting a match on email. So

mysql_num_rows( $result ) == 0 

will always be true.

try

echo $sql

to make sure your SQL looks right. You may not be passing $emlAd correctly to createUser()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜