Checking If The Username Is Available With Ajax
I'm using a basic registration form with AJAX, but the form is not connecting to the database. I'm obviously overlooking something. So here's the field I want to validate. Username
Solution 1:
Just a nitpick on the select statement. Since you only need to get how many rows exist for the entered username you don't need to do a "select *" as depending on the number of columns in your users table you could be returning quite a bit of data. I would revise your query to be like so:
$sql = "select COUNT(username) from members where username=$user_name";
Then you check to make sure that the result of the query equals zero. If it does then the username is available.
I know that the above wasn't an answer to your question but just thought I would point it out since this looks to be a function that is going to get called a lot depending on the traffic on your registration form and the creativity of your visitors.
Solution 2:
Check your query:
$sql = "select * from members where username='$user_name'";
I this the above query should be:
$sql = "select * from members where username=$user_name";
Post a Comment for "Checking If The Username Is Available With Ajax"