Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial php通过url传递参数后同时向数据库写入两条相同记录

php通过url传递参数后同时向数据库写入两条相同记录

Jun 23, 2016 pm 01:47 PM

我通过a.php页面通过url向b.php页面传递了两个参数,并通过b.php页面向mysql数据库写入传递的这两个参数,为什么在数据库中增添了两条相同的记录,但如果不传参数就正常写入一天记录,改为传递一个参数也会写入两个相同的记录,这是写入记录的代码:

<?phpheader("Content-Type:text/html; charset=utf-8");include('MY_PHP_file/mysql_connect.php');$sql = "INSERT INTO user_action (user_id, relation_id, concern_time) VALUES ({$_GET['user_id']}, {$_GET['relation_id']}, now())";// $sql = "INSERT INTO user_action (user_id, relation_id, concern_time) VALUES (0, 9, now())";if(mysql_query($sql));echo '<script>alert(\'操作成功!!\'); location.href=\'user_action.php\';</script>';// else// echo '<script>alert("操作失败,请重试!!"); location.href="user_action.php";</script>';?>
Copy after login

这个问题弄一天了,望大神指导


回复讨论(解决方案)

你不是说搞定了吗?

按照你的 sql 指令串
$sql = "INSERT INTO user_action (user_id, relation_id, concern_time) VALUES ({$_GET['user_id']}, {$_GET['relation_id']}, now())";
当不传递参数时实际执行的是
INSERT INTO user_action (user_id, relation_id, concern_time) VALUES (, , now())
这是错误的指令,不可能有数据插入
但你却说“如果不传参数就正常写入一条记录”,显然这条记录是在其他地方插入的

你的代码不止这一点吧,可能受其他地方影响了。

你不是说搞定了吗?

按照你的 sql 指令串
$sql = "INSERT INTO user_action (user_id, relation_id, concern_time) VALUES ({$_GET['user_id']}, {$_GET['relation_id']}, now())";
当不传递参数时实际执行的是
INSERT INTO user_action (user_id, relation_id, concern_time) VALUES (, , now())
这是错误的指令,不可能有数据插入
但你却说“如果不传参数就正常写入一条记录”,显然这条记录是在其他地方插入的


就是因为传递参数后会插入两条数据,所以有一条是用来测试了!之前极少概率会正确插入一条,所以应该是参数的问题

你不是说搞定了吗?

按照你的 sql 指令串
$sql = "INSERT INTO user_action (user_id, relation_id, concern_time) VALUES ({$_GET['user_id']}, {$_GET['relation_id']}, now())";
当不传递参数时实际执行的是
INSERT INTO user_action (user_id, relation_id, concern_time) VALUES (, , now())
这是错误的指令,不可能有数据插入
但你却说“如果不传参数就正常写入一条记录”,显然这条记录是在其他地方插入的


他的问题感觉就是页面跳转的时候的问题。可能不像他描述的只有这部分的代码,他全部的代码可能在执行这个点击的时候执行了其他插入数据库的操作,能不能加个参数,识别是通过本页面(本点击操作)传递插入值的,也就是mysql中user_id, relation_id, concern_time后再加一个字段s_url然后把值插入进去,看看两条记录中s_url的值是不是一样的

我通过a.php页面通过url向b.php页面传递了两个参数,并通过b.php页面向mysql数据库写入传递的这两个参数

先直接调用b.php 看看是否插入两条记录。
如果b.php正常,则问题在a.php,反之亦然。

只看你提供的代码,是不会插入两条记录,因为只有一条insert语句。

楼主你看下从a页面到b页面的请求头是不是有Referer信息,这个可能会造成重复发送语句的问题。再试试直接在地址栏输入b页面地址带上参数看看会不会写入相同的数据

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

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,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

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

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

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 permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

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...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

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.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

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�...

See all articles