Jump to content

check username against db while being entered


Linrox

Recommended Posts

is it possible to check a username or email address against a mysql database as the user types it in or when he changes to the next required input field,
and if it is not already taken to place a symbol next to the username to show that it is either available or not.

I am still quite new to php.

Thanks

Link to comment
Share on other sites

Short answer is yes.

 

It is more of a JavaScript question.  When the user changes the field, you send an Ajax request to the server, and then your PHP will check it against the DB and send back a status.  Do you use jQuery?  If so, there is a validation plugin which has a remote method which will do what you are looking for.

Link to comment
Share on other sites

Not a 'basic' kind of thing, but still not that hard to do. Need to do some googling on ajax requests and try to understand how it works. Basically - your js code is triggered by the onchange (or an onkey* event) event of your input field. That means as the user types something your js code executes immediately and prepares an http request that is sent to the server as a totally separated task. That task is going to run a php script to do your bidding and return you something - whatever you want. Your js code retrieves the response and then handles it - probably by putting something into the html of your screen.

 

If you have a slow connection to your server this will be problematic.

 

Question - are the possibilities part of a limited (ie, small) set that you know beforehand? If so, you could build an array for your js code to use instead of using ajax to go back to the server on every keystroke.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.