mysql - The problem of repeated entry always occurs in PHP loops
PHP中文网
PHP中文网 2017-05-24 11:30:40
0
4
546

Store the user information in an array, and then use a loop to enter the mysql database. However, occasionally the information of individual users will be entered twice. I don’t know where the logic error is. Please give me some advice:
The logic code is as follows

$data = array(); //用户信息数组 for($i=0;$i alert('$con');parent.location.href='index.php'; ";

What is strange at the moment is that the information entered by individual users is always executed twice (for example, the submitted array only has 5 elements, but the entry into the database produces 10 records)

90% of the entries are normal, only some users will do it, please give some guidance

PHP中文网
PHP中文网

认证高级PHP讲师

reply all (4)
给我你的怀抱

This happens when you use location.href to jump. Some browsers may re-submit the form twice as soon as they are refreshed. There are several solutions. I will just give you an example.

  1. ajax no refresh

  2. When the front-end submits, the back-end generates a token and saves it to the session. When submitting to the back-end, the two tokens are compared

  3. Database for verification

  4. The backend uses 301 or 302 to jump

    巴扎黑

    I don’t see any special problems logically. I can only say that it may be that your front-end submitted two requests, and generally speaking, when inserting data, it is generally judged whether the user exists in the database, but you did not make this judgment, which also caused the information to appear. Ten records

      为情所困

      What you should think of is:

      insert into table (fields...) values(values),(values),(values);
        phpcn_u1582

        Before inserting, judge the value of the database, at least with a unique index.

        In case of individual input errors, it depends on the data in your $data.

          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!