Jump to content

[SOLVED] mysql update


kusal

Recommended Posts

$views++;

echo $views; //2

mysql_query("update vehicles set hits = '$views' where id = '$id' limit 1");

echo $views; //2

 

According to above code hits should update with 2 but it's actually update with 3, why mysql add extra 1

Link to comment
Share on other sites

Hi

 

Can't see any reason. Can you put the SQL into a string and echo it out before you execute it?

 

By the way, is there a reason for the limit clause. Seems pointless (as the if more than 1 row met to WHERE clause a random one would be updated) without an order clause.

 

All the best

 

Keith

Link to comment
Share on other sites

I tried it, query has 2 also. I'm sure that the query is not running two times.

 

This worked  fine until today.

 

if I give a direct value it takes it correctly like this $views = 8;

Link to comment
Share on other sites

session_start();

$date = date("i:s");

echo $_SESSION['test12'] = $_SESSION['test12'].', '.$date;

 

I did test for this page and found out that page is actually loading two time

15:21, 15:22 | 15:25, 15:26 | 15:31, 15:32

 

anyone know a reason for this  :-[

Link to comment
Share on other sites

Pages get requested multiple times for a lot of different reasons -

 

You have javascript code on the page that is doing it; you have a debugging tool in your browser (such as firebug) doing it; your browser is requesting the page twice due to how it handles character encoding; your page is the default document (index.php) and your browser is requesting it twice due to how the favicon.ico file is handled; you have url rewriting that is causing the page to be requested twice; you have something on the page that is including or otherwise causing the code to be executed twice.

 

After you eliminate the things that are within your control (coding on the page that is causing it), you will probably find that you need to use a session variable to detect and prevent multiple page requests to handle the cases that are out of your control.

 

After the point in your code where you have correctly and completely processed the form submission, set a session variable that indicates that the processing is complete. Then at the start of your form processing code, check if that session variable is set and skip the form processing code if it is.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.