I'm creating my first membership script with PHP (using a MySQL database) and I've stubled across a smal problem and can't find the answer anywhere (although I'm sure it's pretty simple).
If a member wants a username (which is set to be unique) that is the same as a current member, the following error gets returned:
Error: Duplicate entry 'desiredusername' for key 1
How can I check if there is already a row in a table with desiredusername as a username before trying to create the row? A function returning TRUE or FALSE is what I'm really looking for.
Thanks in advance,
Rupe
[SOLVED] Finding out if a row exists
Moderator: General Moderators
what about this
have a look at [php_man]mysql_num_rows[/php_man] in the manual
Mark
Code: Select all
if (mysql_num_rows($result) == 0) {
// Add the user
} else {
// Usermame already exists
}Mark
-
starsol
- Forum Newbie
- Posts: 24
- Joined: Thu Jul 31, 2003 8:30 am
- Location: Norfolk, England.
- Contact:
Bech100 wrote:what about this
have a look at mysql_num_rows in the manualCode: Select all
if (mysql_num_rows($result) == 0) { // Add the user } else { // Usermame already exists }
Mark
Cheers, can't believe I missed that