0

I have a table groups with some fields including username.
In my form page, I used an Ajax call to check the username availability. It works. But if two users process the checking at the same time, both of them can see that username is available. How can I avoid this?

fighter
  • 149
  • 1
  • 8
  • 1
    In reality, the username is available until someone processes the request to obtain that username. There isn't much point only telling one user that the username is free as they may not chose that username. I suppose you could just set it as a 'reserved' username for a certain amount of time using a table in your DB, but is it really worth it? – Matt Jan 07 '16 at 07:23
  • before insertion check username.If user one avail that then show message to second user that it has been used try other one – Muhammad Atif Jan 07 '16 at 07:25
  • @Matt yea..it worth it.else it will return integrity constraint error:duplicate entry of key.i cannot redirect to any othor page if this error occure.so a proper data flow require.right? – fighter Jan 07 '16 at 07:43

1 Answers1

0

You need to check username on each keystroke. So when someone start entering username, on each key stroke you need to check username availabity(using ajax). Key press event you can get with using jQuery's .keypress().

Here may be one problem will occur, if before submission of one form some other user took the same username. To overcome with this problem you need to recheck the username availability on form submission as well and if at that time username is not available just provide the message that username already chosen please enter another.

gagan mahatma
  • 336
  • 2
  • 9