PDA

View Full Version : checking for duplicate username


mat
12-22-2002, 09:49 AM
I'm just playing around and making a register/login script. Before inserting a new user it would be a good idea to check for duplicate usernames so i use:


open DBconnection stuff..

Set dupCheck = connection.Execute("SELECT username FROM users WHERE username = '"&user&"'")
If dupCheck("username") > "" Then
Dim dupU
dupU = True
End If

But i get an error on the line:

If dupCheck("username") > "" Then


I'm not sure what i should be putitng there / checking for? NULL? <>, != etc?

scroots
12-22-2002, 11:47 AM
i would go for <> as you want to make sure something does not equal something else.

scroots

Mhtml
12-22-2002, 01:53 PM
I would use Len...


if Len(dupU) > 0 Then
'The name exists
Else
'It doesn't
End if

Roelf
12-22-2002, 02:28 PM
i believe dupCheck is a recordset, so
If dupCheck.BOF and dupCheck.EOF Then
'no user found
Else
'user found
End If

Mhtml
12-22-2002, 03:04 PM
Why use BOF? It will either be at the end or not. Or at the start or not, why not just either of the two?

Roelf
12-22-2002, 03:51 PM
thats the way i learned to test for an empty recordset, then bof AND eof is true, if there is a record, they cannot be true both

Mhtml
12-22-2002, 03:55 PM
Ok, I see it's just double checking. :)

Roelf
12-22-2002, 03:56 PM
if either one of them is true, there can be a record so you have to test for both to be sure there is no record found

oracleguy
12-22-2002, 08:19 PM
Wouldn't you only need to check for EOF because if there is no records, it would be at the end of the records and EOF would be true; right?

Thats the way I've always done it.

mat
12-22-2002, 08:56 PM
cheers, I was curious about that too :confused:

whammy
12-24-2002, 12:35 AM
I agree... I always use:

If NOT rs.EOF Then
' The username exists
Else
' The username doesn't exist
End If

That just seems to make more sense generally, there's no need to check for BOF if you're checking for dupes...

You could do it the other way around too, it doesn't really matter...

If rs.EOF Then
' The username doesn't exist
Else
' The username exists
End If