Link to home
Create AccountLog in
Avatar of Nathan Riley
Nathan RileyFlag for United States of America

asked on

Check Database for Username

I have an html5 form that is for new users to register.  When hitting the submit button I need to check and see if that username is taken before they register.  I'm assuming this is done with javascript, but I don't know that language.
Avatar of Gary
Gary
Flag of Ireland image

Are you using jQuery?
Avatar of Nathan Riley

ASKER

Not yet, but I'm open to do so.
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
On submit you should check if certain records excists in your database per cell.
if excisting throw a message and if all are unique create the row or am i thinking to easely?
Unless there are a very large number of users, then 99.999% of the time there is not going to be a duplicate id.  You have to validate everything on the server before it goes into the database, so the extra traffic and client side code is really a waste of resources. Just check it as part of server side validation and send back an error response like you would for any other field that is a problem. Adding a server and DB hit for something like this is really unnecessary, and adds nothing to the value of the page.

Cd&
Disagree with you Cd&
Since 99.999% of users tend to all want the same kinds of usernames this is a perfect example of presenting a user experience where they are not waiting to see if their request is successful, also add to that, that it is a tiny hit on the server compared to repeatedly doing a submit until they enter a username that is available.
Disagree with you Cd&

That's fine.  I just do what works;  I let folks know what works; then I go for a beer. The correct approach does not change because someone agrees or disagrees or if the wrong approach is adopted. Bloating the page with a Jquery library for a little validation falls right in line with the rest of the wasted resources.

Inefficiency and bloat are never the correct approach when there are effective alternatives, unless you sell servers, hosting, or bandwidth.

Cd&
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
I ended up getting it to work with ajax, thanks for the links guys.

Next related question is here:
https://www.experts-exchange.com/questions/28178981/Username-Database-Check.html