RE: [PHP-DB] check

From: Date: Fri, 27 Oct 2000 17:50:23 +0000
Subject: RE: [PHP-DB] check
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-4002@lists.php.net to get a copy of this message
If usernames are supposed to be unique in your system, I would assume then that username should be a primary key of the members table, correct? If this is the case, why not have the database do the work instead? Try to do an insert into your members table with the new username and if the insert fails because of a violation of the primary key constraint, then you know that the record already exists. ....or.... if you want to continue using the code you are using, then the line <code> $count = count($numrows); </code> is not necessary. You can use the value of $numrow in your if statement as that variable will contain the number of rows returned from your query. HTH Sam Masiello System Analyst Chek.Com (716) 853-1362 x289 smasiello@chekinc.com -----Original Message----- From: bryan [mailto:bryan@concept-factory.com] Sent: Tuesday, October 24, 2000 1:56 PM To: php-db@lists.php.net Subject: [PHP-DB] check I am trying to count through my records to verify a username. If it is already in my Database, print username is already taken. I am having trouble getting my results to come up correctly. here is my code: mysql_select_db("test",$dbcnx); $query = "SELECT * FROM members where username='$username'"; $result = mysql_query($query,$dbcnx) or die("Error in query"); $numrow = mysql_num_rows($result); $count = count($numrows); if ($count != 1) { print "This is a valid username"; } else { print "User-name already in use!"; } Does this even make since? i feel as if I am being over-redundant calling count($numrows), but my logic could be bass-ackwards. Any help or critique would be appreciated! thanks bryan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#4002) next »