内网系统,单号在提交时有做防重复判断,但是相同单号提交一次变成两次。
内网系统,
服务端PHP+MYSQL
数据表字段的值在写入时PHP中有做判断,正常提示相同的单号不可能会重复插入数据的,但是有时候人家操作时明明只提交了一次,但是发现数据一模一样且同一时间同一秒写入了两条。
那位大侠知道怎么回事呀。
回复讨论(解决方案)
估计是连点了两次提交
我目前对于这种情况是前后台两种限制
前台当点击提交按钮时先把提交按钮变灰,并且不可点 ,然后再ajax向后台传值 返回结果后视程序逻辑转跳或者恢复按钮
后台插入前先判断是否已经有这条数据了(根据一个或几个不可能重复的字段来判断) 如果没有才进行插入.
额,如果是form表单提交的话 也可以用js来代替submit 点击后js先禁用按钮,再用js进行submit
只点了一次,但这种机率一个月会遇到一两次,我PHP代码中有先查询当前这个单号是否存在,如不存在才能执行写入数据库的作业的。所以纠结是什么情况出现的。。。
具体要看你写的代码,从源头解决问题。
秒并发问题。
例如有两次请求A,B同时到达
AB,都过了判断是否重复那个位置,然后当A插入后,B都会跟着插入。
可以这样写来避免重复插入。
例如test表有两个字段 name,value
INSERT INTO test(name, value) SELECT 'fdipzone', '123' FROM DUAL WHERE 'fdipzone' NOT IN (SELECT name FROM test);
既然是内网系统,并发量肯定不会很高,多个用户同时点击按钮的概率更低。
做好前端防止重复提交,后台验证提交即可。
秒并发问题。
例如有两次请求A,B同时到达
AB,都过了判断是否重复那个位置,然后当A插入后,B都会跟着插入。
可以这样写来避免重复插入。
例如test表有两个字段 name,value
INSERT INTO test(name, value) SELECT 'fdipzone', '123' FROM DUAL WHERE 'fdipzone' NOT IN (SELECT name FROM test);
我觉得您的写法应该可取,在插入语句里再判断一次。
虽然多个用户同时提交相同的内容的概率很低,但楼主也只是“有时候”出现
撇开程序的问题,这种情况在十年前经常出现。原因是浏览器的升级版本不稳定,导致一个请求发送两次数据,当然现在都已经修复了。不过怀旧者非要使用的话,出现问题也就很正常了
另一种情况是:表单不是提交到本页,或提交是由 ajax 完成的,此时如果用户的鼠标过于劳累,单单击变成了双击。从而造成二次提交也是可能的
防范这些非人为的故障可以在接收时做一下判断
session_start();if(isset($_SESSION['post']) && $_SESSION['post'] == md5(serialize($_POST))) return;$_SESSION['post'] = md5(serialize($_POST));//正常的提交处理

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
