I'm creating a registration page and onchange, I would like it to check the SQL database to see if the username is already in use, and I understand I'll need AJAX for this, but I'm not quite sure how.
Any ideas? |:
Check SQL Table
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Check SQL Table
You don't need Ajax for that, but you can use it. You just need to do a SELECT when they submit the form. If it exists then respond with an error status. If it does not exist then create the record and respond with a success status.
(#10850)
Re: Check SQL Table
arborint wrote:You don't need Ajax for that, but you can use it. You just need to do a SELECT when they submit the form. If it exists then respond with an error status. If it does not exist then create the record and respond with a success status.
My bad I left some stuff out D: I know how to do that much; at the moment, I have it check with a PHP function whether or not it exists, but I'd like for a green button to appear if it does not exist, and a red one to indicate it's taken.
Sorry for that ambiguity.
-
limitdesigns
- Forum Commoner
- Posts: 25
- Joined: Sat Feb 06, 2010 9:05 pm
Re: Check SQL Table
So, have the onblur() event of the username text field call an AJAX function which returns either '' (for username is available) or some error message (like, "Username is already in use"). Then, have a check in the javascript: if the AJAX script returns '', then you can change the button's color to green. If it has something (the error), then you can change the button's color to red.
If you aren't using it already, jQuery is perfect for this sort of thing. I just did this myself on a website I'm developing for and it works perfectly, and it took only 15 minutes.
If you aren't using it already, jQuery is perfect for this sort of thing. I just did this myself on a website I'm developing for and it works perfectly, and it took only 15 minutes.
Re: Check SQL Table
Well I looked into some jquery tutorials and didn't quite find any ways to do what I'm looking for ( probably cause they're all beginner tuts )
Would you care to go into a little more detail?
Would you care to go into a little more detail?