PDA

View Full Version : checking username


Baleric
05-21-2006, 11:56 AM
hey guys,
was wondering how i would check to see if a username is taken when a user trys to register with me web site,

so if that a username is entered that already exists then u get redirected to register.asp?id=12

textfield name is "username" and field name in DB is called "username"


thanks in advance...

baleric

Brandoe85
05-21-2006, 11:40 PM
Query your table where the username = the username they entered and if you get a row back, you know it's in use already.

Good luck;

Roelf
05-22-2006, 07:59 AM
or create a unique constraint on the database column, you dont have to query then before you do the insert, the insert will simply fail. The response from the database will give you the clue to redirect.

Baleric
05-22-2006, 09:09 AM
or create a unique constraint on the database column, you dont have to query then before you do the insert, the insert will simply fail. The response from the database will give you the clue to redirect.

i have done this using ms access DB, but i simply get a error stateing
The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.

how do i do the redirect on recieving this error?

thanks for the help do far.

baleric

Roelf
05-22-2006, 09:21 AM
somewhere before the line where you execute the insert, enter the following line:
On Error Resume Next
which will cause the pagecode to continue executing when an error occurs
then check for errors using
If Err.Number <> 0 Then
'do your error handling (in this case redirect) here
End If
'continue processing for the case where there is no error

Baleric
05-22-2006, 10:07 AM
thank you ill give it a go soon :)

thanks alot for your help!!

cheers

baleric

Baleric
05-23-2006, 10:51 AM
cheers mate , it worked great, thanks again.

Zvona
05-23-2006, 12:22 PM
Also remember to clear the error (in general):

On Error Resume Next
...
If Err.Number <> 0 Then
...
...
Err.Clear
End If
...
On Error Goto 0