How to use UNIQUE of PHP and MySQL to ensure that the user name is unique like JD.com registration?
phpcn_u1582
phpcn_u1582 2017-06-28 09:23:08
0
3
838

I think that such a quick way to determine the user name duplication is to set the user name field UNIQUE, and then write to catch the exception.
But I tried it and found that the actual operation is not that simple. If the user name is required to be unique, just write the table to see the exception. If it is repeated, it can return false, but if it is successful, the written data will be incomplete. We What is really needed is to write the registration information submitted by the user to the table together. I thought about it and realized that this operation can only be achieved through transactions. As long as the transaction is not committed, the table will not be actually written, but we have already learned that the table Is this piece of data conflicting? I don’t know if my understanding is correct. Or it is achieved through other means. Isn’t it appropriate to judge by select query for a large amount of data?

phpcn_u1582
phpcn_u1582

reply all(3)
黄舟

Isn’t it generally true that ajax will do the query after the front-end input is completed? When submitting, check it again before inserting it into the library. It is safer to be unique.

为情所困

According to the name entered by the user, check the database and it will be ok. If there is a result, it will prompt that it is occupied. If there is no result, it can be used. If someone submits it first and then prompts that it is occupied while entering other information, it will be ok. Please consider your words. Yes, the probability of this is very low and it is acceptable

学习ing

Check it in the database

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!