Ask for updated statements, increase the number of questions!

Source: Internet
Author: User
SELECT * from user where names= ' test ';:?? SQL statements
Update user SET num= $nums where names = ' $test ';:?? SQL add-times statement
114:?? Number of stores in $nums database +1
113:?? Number of stores in $row [' Num '] Database
1:?? $row the ID of the [' ID ']user table
Test:?? $row the test data in the [' names '] Database

This is the number of access clicks for the names value. Strange is a link click words, the number of times is increased 2 each time, and this link new window open run, but only added once, refresh also added once

What is the reason for this? Where did it go wrong? The following is the query UPDATE statement and the contents of the creation table.

$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 '");
Or: mysql_query ("Update user SET num= $num +1 where names = ' $test '");

CREATE TABLE IF not EXISTS ' user ' (
' id ' int (ten) unsigned not NULL auto_increment,
' Names ' varchar (+) 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);

Current page-href= "? Names=test"
Click the page link, add two times record, right-click Link New window open run and the current page refresh only add one time record! It's weird, what did I do wrong?


Reply to discussion (solution)

$row = Mysql_fetch_array ($result);
$nums = $row [' num ']+1;
mysql_query ("Update user SET num= $nums where names = ' $test '");
Or: mysql_query ("Update user SET num= $num +1 where names = ' $test '");

$nums = $row [' num ']+1; Already added 1, bottom or how do I add 1? "SET num= $num +1"

In addition, the value passed in, you do not judge it?

In addition, the value passed in, you do not judge it?


$test = $_get[' names ');
This is just a simple notation,
$nums = $row [' num ']+1; this is the one I'd like to visit once to add to the database.
Other than that
mysql_query ("Update user SET num= $num +1 where names = ' $test '");
This is supposed to be a mistake, num=num+1.
The code in this post I tested, not considering injection or other, just under normal circumstances is OK,
Is there a question that the page itself is placed on a link, or through an external click link to enter this? Namestest ... In this case, the NUM field is incremented by 1, which is two times more, but if you click the link to open it through a new window, or the current page refreshes, the NUM field will be added 1 times!
Yes, I don't understand why, by the way, this PHP cookie
if (!isset ($_cookie[' visits ')) $_cookie[' visits '] = 0;
$visits = $_cookie[' visits ') + 1;
Setcookie (' visits ', $visits, time () + 60);
This code will work in the GBK file, but not in UTF-8, which is why? How to Handle

Look at your description is rather strange, can debug like this.
$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);
?>

After the run to see Sos.txt, whether 3 sentences, if six sentence that means the execution of two times.

Look at your description is rather strange, can debug like this.
^ ^.


73
74
Update
74
75
Update
75
76
Update
76
77
Update
This is a click on the visit, my lien points two times!
The following is what I
73
74
Update
74
75
Update
75
76
Update
76
77
Update
77
78
Update
78
79
Update
A new window opens to run, one time the current page refreshes

Then, I found a more ridiculous thing!
I usually use Firefox browser to test, and today occasionally with IE test a bit, the results! In the IE8 inside, but is no matter how I new window, refresh, the current link click, are only added once, it is normal! Then, with Firefox re-refresh, new window, the current link, strange things happened, but all normal!
Then the second if it is used IE or mobile phone browser first access, normal, if the next day with Firefox first access, it is two times increased!
Don't understand! Both local and server have been tested, that's it! Which part of my footsteps is wrong?

You only describe the phenomenon and do not give the test code.
This is not good to say, it may be that your code is writing a problem (HTML section)

You can be sure that your PHP is not a problem and see how many calls there are.
Look at the request from Firebug network.

You can be sure that your PHP is not a problem and see how many calls there are.
Look at the request from Firebug network.


Firebug, I really did not expect to have this function, forgot, these days and normal ...
First knot paste, thank you!
  • Related Article

    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.