Intranet system, the number at the time of submission has to do anti-duplication judgment, but the same number submitted once changed to two times.

Source: Internet
Author: User
Intranet system,
Service-Side Php+mysql
The value of the Data table field is written in PHP to make a judgment, the normal hint of the same number can not be repeated insert data, but sometimes when the operation was clearly submitted only once, but found that the same time and the same second write two.
The warrior knows what's going on.


Reply to discussion (solution)

It's probably a two-time commit.

I currently have two restrictions on this situation, both front and rear.

Front desk when clicking the Submit button to turn the Submit button gray, and not point, and then Ajax to the background value returned results after the program logic to jump or restore the button

Before inserting in the background, it is necessary to determine if the data is already in place (judging by one or several fields that cannot be duplicated).

The amount, if it is a form form submission can also use JS instead of submit click JS First Disable the button, and then use JS to submit

Only point once, but this probability one months will meet one or two times, I PHP code in the first query whether the current number exists, such as does not exist in order to execute the job written to the database. So the tangle is what the situation arises ...

Depending on the code you write, solve the problem at the source.

seconds concurrency problem.
For example, there are two requests, a and a
AB, after judging whether to repeat the position, and then when a is inserted, B will follow the insert.

This can be written to avoid repeated insertions.
For example, the test table has two fields Name,value

INSERT into Test (name, value) of select ' Fdipzone ', ' 123 ' from DUAL WHERE ' Fdipzone ' isn't in (select name from test);

Since it is intranet system, the concurrency is certainly not very high, many users simultaneously click the button the probability is lower.
Do the front-end to prevent duplicate submission, background verification submission.

seconds concurrency problem.
For example, there are two requests, a and a
AB, after judging whether to repeat the position, and then when a is inserted, B will follow the insert.

This can be written to avoid repeated insertions.
For example, the test table has two fields Name,value

INSERT into Test (name, value) of select ' Fdipzone ', ' 123 ' from DUAL WHERE ' Fdipzone ' isn't in (select name from test);

I think your writing should be preferable, in the INSERT statement to judge again.

Although the probability of multiple users submitting the same content at the same time is very low, the landlord is only "sometimes" appear
Aside from the problems of the procedure, this situation was often seen ten years ago. The reason is that the upgrade version of the browser is not stable, causing a request to send two data, of course, has now been fixed. But if the nostalgic person has to use it, it's normal to have problems.
Another scenario is that the form is not submitted to this page, or the submission is done by Ajax, and if the user's mouse is too tired, it simply becomes a double-click. So it's possible to commit two commits.

To prevent these non-human failures can be judged at the time of reception

Session_Start (), if (Isset ($_session[' post ") && $_session[' post '] = = MD5 (serialize ($_post))) return;$_ Session[' post '] = MD5 (serialize ($_post));//Normal commit processing
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.