select * from user where names='test';:??sql语句
update user SET num=$nums where names = '$test';:??sql增加次数语句
114:??$nums数据库里的储存次数+1
113:??$row['num']数据库里的储存次数
1:??$row['id']user表里的ID
test:??$row['names']数据库里的test数据
这个是names值的访问点击次数。奇怪的是一个链接点击的话,次数是每次增加2,而这个链接新窗口打开运行,却只增加一次,刷新同样增加一次
这是什么原因呀?哪里出错了?以下是查询更新语句和创建表的内容。
$test = $_GET['names'];
$sql = "select * from user where names='$test'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$nums = $row['num']+1;
mysql_query("update user SET num=$nums where names = '$test'");
或者:mysql_query("update user SET num=$num+1 where names = '$test'");
CREATE TABLE IF NOT EXISTS `user` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`names` varchar(15) NOT NULL DEFAULT '',
`num` tinyint(1) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `names` (`names`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk AUTO_INCREMENT=1 ;
INSERT INTO `user` (`id`, `names`, `num`) VALUES
(1, 'test', 0);
当前页面 - href="?names=test"
点击页面链接,增加两次次数记录,右键链接新窗口打开运行和当前页面刷新只增加一次记录!很是奇怪,到底我哪做错了?
回复讨论(解决方案)
$row = mysql_fetch_array($result);
$nums = $row['num']+1;
mysql_query("update user SET num=$nums where names = '$test'");
或者:mysql_query("update user SET num=$num+1 where names = '$test'");
$nums = $row['num']+1;已经加1了,下边的或者 怎么还加1?【SET num=$num+1】
另外,传进来的值,你不做判断吗?
另外,传进来的值,你不做判断吗?
$test = $_GET['names'];
这个只是简单的写法,
$nums = $row['num']+1;这个是我想访问一次就增加一次到数据库而已
另外
mysql_query("update user SET num=$num+1 where names = '$test'");
这个应该是写错,是num=num+1
这帖子里的代码我测试过,不考虑注入或其它,只是在正常的情况下是可以的,
就是有一点疑问,这个页面本身上放一个链接,或是通过外部点击链接进入这个?namestest ……这样子的话,num字段是会连续增加1,也就是变成了增加两次了,可是如果是点击这个链接通过 新窗口打开,或是当前页面刷新,num字段就会正常加1次!
是这个不明白为什么另外顺便问一下这个PHP COOKIES的
if (!isset($_COOKIE['visits'])) $_COOKIE['visits'] = 0;
$visits = $_COOKIE['visits'] + 1;
setcookie('visits', $visits, time() + 60);
这样的代码放在gbk文件中就可以正常运行,但在UTF-8中却不行,这是为什么?如何处理
看你的描述是比较奇怪,可以这样调试。
$test = $_GET['names'];
$sql = "select * from user where names='$test'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
file_put_contents('sos.txt', $row['num'].PHP_EOL,FILE_APPEND );
$nums = $row['num']+1;
file_put_contents('sos.txt', $nums.PHP_EOL,FILE_APPEND );
mysql_query("update user SET num=$nums where names = '$test'");
file_put_contents('sos.txt', 'update'.PHP_EOL,FILE_APPEND );
?>
运行后看看sos.txt,是否3句,如果六句那就表示执行了两次。
看你的描述是比较奇怪,可以这样调试。
^^。
73
74
update
74
75
update
75
76
update
76
77
update
这个是点击访问后的,我连战点了两次!
这个下面的内容是我
73
74
update
74
75
update
75
76
update
76
77
update
77
78
update
78
79
update
一次新窗口打开运行,一次当前页面刷新
然后,我发现了一个更为可笑的事!
我一般都是用FIREFOX火狐浏览器进行测试,今天偶尔用IE测试了一下,结果!在IE8里面,却是不管我怎么新窗口,刷新,当前链接点击,都是只增加一次,很是正常!然后,用火狐再刷新,新窗口,当前链接,奇怪的事发生了,却全部正常了!
然后第二如果又是用IE或是手机等浏览器先访问,就正常,如果第二天用火狐先访问,就又是二次增加!
不明白!本地和服务器都测试过了,就这样!是我哪个地方步子错了?
你只描述了现象,并没有给出测试代码。
这就不好说了,可能是你的代码写的有问题(html 部分)
可以确定你的php没有问题,看看那里调用多次了。
看看firebug network那里的请求
可以确定你的php没有问题,看看那里调用多次了。
看看firebug network那里的请求
firebug , 我真没想到有这个功能,忘记了,这几天又正常……
先结贴吧,感谢大家!

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version
Recommended: Win version, supports code prompts!

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