kusal Posted June 9, 2009 Share Posted June 9, 2009 $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 Quote Link to comment https://forums.phpfreaks.com/topic/161503-solved-mysql-update/ Share on other sites More sharing options...
fenway Posted June 9, 2009 Share Posted June 9, 2009 Echo the actual query... it's probably getting run twice. Quote Link to comment https://forums.phpfreaks.com/topic/161503-solved-mysql-update/#findComment-852280 Share on other sites More sharing options...
kickstart Posted June 9, 2009 Share Posted June 9, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/161503-solved-mysql-update/#findComment-852281 Share on other sites More sharing options...
kusal Posted June 9, 2009 Author Share Posted June 9, 2009 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; Quote Link to comment https://forums.phpfreaks.com/topic/161503-solved-mysql-update/#findComment-852295 Share on other sites More sharing options...
kusal Posted June 9, 2009 Author Share Posted June 9, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/161503-solved-mysql-update/#findComment-852358 Share on other sites More sharing options...
PFMaBiSmAd Posted June 9, 2009 Share Posted June 9, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/161503-solved-mysql-update/#findComment-852370 Share on other sites More sharing options...
kusal Posted June 9, 2009 Author Share Posted June 9, 2009 Thanks, What ever causing it only happens to this page. Quote Link to comment https://forums.phpfreaks.com/topic/161503-solved-mysql-update/#findComment-852380 Share on other sites More sharing options...
kusal Posted June 9, 2009 Author Share Posted June 9, 2009 I don't know why, but it caused by a nested table, when I remove the form with the nested table it was all good again Quote Link to comment https://forums.phpfreaks.com/topic/161503-solved-mysql-update/#findComment-852397 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.