Re: To check for existing user in database

From: Date: Fri, 16 Jan 2009 07:01:15 +0000
Subject: Re: To check for existing user in database
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-286486@lists.php.net to get a copy of this message
2009/1/15 tedd <tedd.sperling@gmail.com>: > At 9:46 AM -0800 1/15/09, Chris Carter wrote: > > Chris: > > That's not the way I would do it. After establishing a connection with the > database, I would use the query: > > $query "SELECT email FROM owners WHERE email = '$emailAddress' ": > $result = mysql_query($query) or die(mysql_error()); > > if(mysql_affected_rows()) > { > // then report a duplicate email/record. > } > else > { > // else insert a new record in the dB. > } > > HTH's > > tedd You want to use mysql_num_rows() there instead of mysql_affected_rows(). (Just a typo in this case, I suspect, but for the benefit of the less experienced it's worth pointing out.) For the newer PHP users, mysql_num_rows() tells you the number of rows you found with a SELECT query, while mysql_affected_rows() tells you how many rows you affected with an INSERT, UPDATE, REPLACE INTO, or DELETE query. Regards, Torben

« previous php.general (#286486) next »