Linrox Posted January 22, 2015 Share Posted January 22, 2015 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted January 22, 2015 Share Posted January 22, 2015 Yes. You would use the on change event to send an AJAX request to the server and return a value to let you know if is taken or not. Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted January 22, 2015 Share Posted January 22, 2015 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. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 22, 2015 Share Posted January 22, 2015 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.