Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check to see if username exists before submitting form 1

Status
Not open for further replies.

jasonhuibers

Programmer
Sep 12, 2005
290
CA
Is there a way I can check to see if username exists in database BEFORE submitting the form?
 
you could use something like AJAX to make a request to the database, but this would only tell you that at time of asking it was not there, it may be when the actual insert to the database is done.

Greg Griffiths
Livelink Certified Developer & ECM Global Star Champion 2005 & 2006
 
Yes sorry about that....

I have a form users fill out and when they click the submit the data is posted to the asp page in the <form action="InsertClientInfo.asp"...

However before posting the data I need to check if the username column they enter exists or not against a database. If the username entered exists then the page should not be submitted becausde I want to return USERNAME ALREADY EXISTS, if the username does not exists then post the data to the InsertClientInfo.asp page...

Any suggestions or is there a simple way to check if the username exists before submitting the form?
 
It feels like you're making this more complicated than it needs to be. Why not have a button beside the username textbox which the user clicks to check the username is available, if it is available the name is inserted into the db with the rest of the fields blank (to make sure no other users take the username while he is filling out the rest of his information) if not it returns that he needs to choose a new username.

The user can then fill out any extra information you require and submit his data to you, whereupon you update the row created.

You'd need a clean up script to run in case the person backed out of sign up, should be simple to delete rows which have certain fields blank.

~Ben
Occasional sparks in a darkened room
 
if it is mandatory that the username is unique,
ggriffit remark is correct:
"but this would only tell you that at time of asking it was not there, it may be when the actual insert to the database is done.".

You can not force uniqueness this way. The only way to do it right is a unique index on the field "username".
Then: forget client side testing. Simply do an INSERT and watch for the "duplicate valalue" error.
 
But if you're using a sign in system to a website you can't have 2 people with the same username. I don't think it's about uniqueness in the DB, but about making it possible for users to sign in without the DB getting confused who is attempting to sign in.

~Ben
Occasional sparks in a darkened room
 
... so you have a table with all usernames. in that table typically username and email address are unique fields.
New user may register with unique values. If (s)he provides a value that already exist, you'll get a nice error during INSERT, which you can use to redirect to a warning page.
If a user forgets a password, you simply ask for the email address to send it to; email is unique, a query with email address finds only 1 record.
If a user logs in with userid, there is only 1 record to check.
 
CLOSED

I will have the username and password columns on one form - do the validation against the db and if exists then return msg. If does not exists then submit form to next page..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top