I have a register form that goes through the following steps:
- Fill in user information (name,adress,etc.) and username
- If user presses the submit button, it is checked if username is already in the database or not
- If username is already in use, he must rename username, if not, it is shown what he has entered (name,adress etc.).
- He has to confirm the website rules and that his input data is correct. If he presses the confirm button, a row with his details and username will be inserted in the database.
I do not want to insert the row in the database after step 2., because I dont want rows from users in my database that did not confirm the rules. Also I want to keep step 3., so the user can make sure that his data is correct. Unfortunately, at the moment the code cant prevent the unlikely case that two user register at the same time with the same username. How does one prevent this case in general? I know there are a lots of php forms out there who proceed with these 4 steps.
EDIT: Sorry, that I didn't make it clear enough: I am not concerned about double entries in my database, this can be prevented by setting the username field unique. I want to know how can I check in step 2. that the username is not used in the database AND not used by any other user who is currently using the registration form.