Currently I'm using Ajax to check register validation, but I feel if the internet connection is not good enough, sometimes Ajax is not working properly and it makes users register with the same username. So how can I double check the register validation to avoid the duplicate usernames in my database?
-
1in your php upload user script, perform a sql query to check the name, and on success/failure of that, then continue the upload script?Mupps– Mupps2013-03-27 05:20:11 +00:00Commented Mar 27, 2013 at 5:20
-
do you using Ajax to registration itself?egig– egig2013-03-27 05:25:59 +00:00Commented Mar 27, 2013 at 5:25
-
@Charlie I'm using Ajax to do the validation.soundsticks– soundsticks2013-03-27 05:27:20 +00:00Commented Mar 27, 2013 at 5:27
3 Answers
If the field in your database is set to UNIQUE this won't be a problem since an error will be returned i.e.
CREATE TABLE user (
username VARCHAR(20) UNIQUE NOT NULL,
...
)
When an INSERT is run on this table but the potential username is already taken, an error will be kicked back.
Should I mention that while client-side validation is all well and good for being fancy on your webpage with the pop-up divs and highlighted spans, validation should always be rechecked on the server-side.
Comments
Other than setting the constraint on the column username to be unique, you should be doing a QUERY prior to creating a record to check for any errors, sounds like you are relying on just Javascript to validate your input.
Solve your validation first! Don't depend on javascript doing it, need it on the front end (html view) and backend code (php)
Comments
well its just an idea, I am pretty sure You do the validation on change or blur event of the input. But the registration will be done by submit button. If I right, Just add some script to the registration-proccess-page that check if the username is exist or not, if exist, just redirect back to the registration page with some error variable on $_SESSION or URL/$_REQUEST. That error variable can be used to tell user what's goin wrong. . good luck !