RE: [PHP] PHP Add +1 mysql updates by 2?
On Fri, 2010-11-26 at 22:29 -0800, Tommy Pham wrote: -Original Message- From: Richard West [mailto:p...@cbnisp.com] Sent: Friday, November 26, 2010 9:40 PM To: Peter Lind Cc: Tommy Pham; Tamara Temple; PHP General Mailing List Subject: Re: [PHP] PHP Add +1 mysql updates by 2? I took that into consideration so I added the update at the very end of document... Still the same, RD snip Things to consider as part of your application design/flow: 1) Are you doing all PHP processing (application initialization, DB retrieval, user preference settings, etc.) before any header, echo, print, printf, output buffer, etc... ? At which point is the update done? 2) Are you sure the DB update is only called for or included/required once for that particular URL request? 3) Do you any have other page (js - or in page ajax calls, css, php, html, etc) that requests the page (with the update) again, as Peter mentioned? It will help you if you do an UML or a flow chart of the application flow. Regards, Tommy Because you're running the query as a response to a GET call, the browser is allowed to call it multiple times and grab select parts of the output to speed up rendering of the page. I've run into this before, and it's annoying. There are basically two ways to prevent this. Have the page called as part of a POST request, which is preferred as GET requests should never change data, hence why browsers are allowed to request them in a slightly different way to speed up the page display times. The second way is to also update a timestamp in the DB, and then before you update check to see if it has been updated within a certain time period. Depending on what you're updating this for (stat counter, etc) then this may not work. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] PHP Add +1 mysql updates by 2?
First let me say thanks to everyone who replied! Ashley, I got it fixed but I have not a clue what did it :) RD On Nov 27, 2010, at 6:49 AM, Ashley Sheridan wrote: On Fri, 2010-11-26 at 22:29 -0800, Tommy Pham wrote: -Original Message- From: Richard West [mailto:p...@cbnisp.com] Sent: Friday, November 26, 2010 9:40 PM To: Peter Lind Cc: Tommy Pham; Tamara Temple; PHP General Mailing List Subject: Re: [PHP] PHP Add +1 mysql updates by 2? I took that into consideration so I added the update at the very end of document... Still the same, RD snip Things to consider as part of your application design/flow: 1) Are you doing all PHP processing (application initialization, DB retrieval, user preference settings, etc.) before any header, echo, print, printf, output buffer, etc... ? At which point is the update done? 2) Are you sure the DB update is only called for or included/required once for that particular URL request? 3) Do you any have other page (js - or in page ajax calls, css, php, html, etc) that requests the page (with the update) again, as Peter mentioned? It will help you if you do an UML or a flow chart of the application flow. Regards, Tommy Because you're running the query as a response to a GET call, the browser is allowed to call it multiple times and grab select parts of the output to speed up rendering of the page. I've run into this before, and it's annoying. There are basically two ways to prevent this. Have the page called as part of a POST request, which is preferred as GET requests should never change data, hence why browsers are allowed to request them in a slightly different way to speed up the page display times. The second way is to also update a timestamp in the DB, and then before you update check to see if it has been updated within a certain time period. Depending on what you're updating this for (stat counter, etc) then this may not work. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] PHP Add +1 mysql updates by 2?
PS: PEBKAC I figure :) On Nov 27, 2010, at 6:49 AM, Ashley Sheridan wrote: On Fri, 2010-11-26 at 22:29 -0800, Tommy Pham wrote: -Original Message- From: Richard West [mailto:p...@cbnisp.com] Sent: Friday, November 26, 2010 9:40 PM To: Peter Lind Cc: Tommy Pham; Tamara Temple; PHP General Mailing List Subject: Re: [PHP] PHP Add +1 mysql updates by 2? I took that into consideration so I added the update at the very end of document... Still the same, RD snip Things to consider as part of your application design/flow: 1) Are you doing all PHP processing (application initialization, DB retrieval, user preference settings, etc.) before any header, echo, print, printf, output buffer, etc... ? At which point is the update done? 2) Are you sure the DB update is only called for or included/required once for that particular URL request? 3) Do you any have other page (js - or in page ajax calls, css, php, html, etc) that requests the page (with the update) again, as Peter mentioned? It will help you if you do an UML or a flow chart of the application flow. Regards, Tommy Because you're running the query as a response to a GET call, the browser is allowed to call it multiple times and grab select parts of the output to speed up rendering of the page. I've run into this before, and it's annoying. There are basically two ways to prevent this. Have the page called as part of a POST request, which is preferred as GET requests should never change data, hence why browsers are allowed to request them in a slightly different way to speed up the page display times. The second way is to also update a timestamp in the DB, and then before you update check to see if it has been updated within a certain time period. Depending on what you're updating this for (stat counter, etc) then this may not work. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP Add +1 mysql updates by 2?
Hey guys, I've never run into this before. I have a field in mysql for page views. So I pull out value and do +1 to new value - after UPDATE SET it has incremented by 2? $val = $row['a_downloads'] ; $new_val = $val+1; mysql_query(UPDATE cbn_articles SET a_downloads='$new_val' WHERE a_id = '.$_GET['id'].' ); Any ideas? What am I missing? RD -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Add +1 mysql updates by 2?
On Nov 26, 2010, at 8:36 PM, Richard West wrote: Hey guys, I've never run into this before. I have a field in mysql for page views. So I pull out value and do +1 to new value - after UPDATE SET it has incremented by 2? $val = $row['a_downloads'] ; $new_val = $val+1; mysql_query(UPDATE cbn_articles SET a_downloads='$new_val' WHERE a_id = '.$_GET['id'].' ); Any ideas? What am I missing? RD a_downloads wouldn't happen to be an autoincrement value, would it? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP Add +1 mysql updates by 2?
-Original Message- From: Tamara Temple [mailto:tamouse.li...@gmail.com] Sent: Friday, November 26, 2010 7:54 PM To: Richard West Cc: PHP General Mailing List Subject: Re: [PHP] PHP Add +1 mysql updates by 2? On Nov 26, 2010, at 8:36 PM, Richard West wrote: Hey guys, I've never run into this before. I have a field in mysql for page views. So I pull out value and do +1 to new value - after UPDATE SET it has incremented by 2? $val = $row['a_downloads'] ; $new_val = $val+1; mysql_query(UPDATE cbn_articles SET a_downloads='$new_val' WHERE a_id = '.$_GET['id'].' ); Any ideas? What am I missing? RD a_downloads wouldn't happen to be an autoincrement value, would it? IIRC, the auto_increment should only increment on an INSERT statement and the field is omitted. Besides, in MySQL, auto_increment must also be part of the primary key. From Richard's query, I'd say that his primary key field is most likely a_id. IMO, the best way to count something is to set the field to an int(eger) type. Then just run 'UPDATE table_name SET count_field = count_field +1 WHERE criteria_column = $criteria'. This is more safe as you many have simultaneous users downloading. This would ensure an accurate count, whereas your logic wouldn't. Regards, Tommy PS: Richard, you should validate and sanitize all inputs. Your query is prone to injection attack (deletion of rows or your entire DB deleted). Use either mysql_escape_string or, better yet, mysqli to prepare the statement and bind the parameters. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Add +1 mysql updates by 2?
No On Nov 26, 2010, at 10:53 PM, Tamara Temple wrote: On Nov 26, 2010, at 8:36 PM, Richard West wrote: Hey guys, I've never run into this before. I have a field in mysql for page views. So I pull out value and do +1 to new value - after UPDATE SET it has incremented by 2? $val = $row['a_downloads'] ; $new_val = $val+1; mysql_query(UPDATE cbn_articles SET a_downloads='$new_val' WHERE a_id = '.$_GET['id'].' ); Any ideas? What am I missing? RD a_downloads wouldn't happen to be an autoincrement value, would it? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Add +1 mysql updates by 2?
Hey Tommy, I get the same when seting it to a_downloads=a_downloads+1 It still increments by 2 I've never run into this before. RD On Nov 26, 2010, at 11:45 PM, Tommy Pham wrote: -Original Message- From: Tamara Temple [mailto:tamouse.li...@gmail.com] Sent: Friday, November 26, 2010 7:54 PM To: Richard West Cc: PHP General Mailing List Subject: Re: [PHP] PHP Add +1 mysql updates by 2? On Nov 26, 2010, at 8:36 PM, Richard West wrote: Hey guys, I've never run into this before. I have a field in mysql for page views. So I pull out value and do +1 to new value - after UPDATE SET it has incremented by 2? $val = $row['a_downloads'] ; $new_val = $val+1; mysql_query(UPDATE cbn_articles SET a_downloads='$new_val' WHERE a_id = '.$_GET['id'].' ); Any ideas? What am I missing? RD a_downloads wouldn't happen to be an autoincrement value, would it? IIRC, the auto_increment should only increment on an INSERT statement and the field is omitted. Besides, in MySQL, auto_increment must also be part of the primary key. From Richard's query, I'd say that his primary key field is most likely a_id. IMO, the best way to count something is to set the field to an int(eger) type. Then just run 'UPDATE table_name SET count_field = count_field +1 WHERE criteria_column = $criteria'. This is more safe as you many have simultaneous users downloading. This would ensure an accurate count, whereas your logic wouldn't. Regards, Tommy PS: Richard, you should validate and sanitize all inputs. Your query is prone to injection attack (deletion of rows or your entire DB deleted). Use either mysql_escape_string or, better yet, mysqli to prepare the statement and bind the parameters. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Add +1 mysql updates by 2?
On Saturday, November 27, 2010, Richard West p...@cbnisp.com wrote: Hey Tommy, I get the same when seting it to a_downloads=a_downloads+1 It still increments by 2 I've never run into this before. RD On Nov 26, 2010, at 11:45 PM, Tommy Pham wrote: -Original Message- From: Tamara Temple [mailto:tamouse.li...@gmail.com] Sent: Friday, November 26, 2010 7:54 PM To: Richard West Cc: PHP General Mailing List Subject: Re: [PHP] PHP Add +1 mysql updates by 2? On Nov 26, 2010, at 8:36 PM, Richard West wrote: Hey guys, I've never run into this before. I have a field in mysql for page views. So I pull out value and do +1 to new value - after UPDATE SET it has incremented by 2? $val = $row['a_downloads'] ; $new_val = $val+1; mysql_query(UPDATE cbn_articles SET a_downloads='$new_val' WHERE a_id = '.$_GET['id'].' ); Any ideas? What am I missing? RD a_downloads wouldn't happen to be an autoincrement value, would it? IIRC, the auto_increment should only increment on an INSERT statement and the field is omitted. Besides, in MySQL, auto_increment must also be part of the primary key. From Richard's query, I'd say that his primary key field is most likely a_id. IMO, the best way to count something is to set the field to an int(eger) type. Then just run 'UPDATE table_name SET count_field = count_field +1 WHERE criteria_column = $criteria'. This is more safe as you many have simultaneous users downloading. This would ensure an accurate count, whereas your logic wouldn't. Regards, Tommy PS: Richard, you should validate and sanitize all inputs. Your query is prone to injection attack (deletion of rows or your entire DB deleted). Use either mysql_escape_string or, better yet, mysqli to prepare the statement and bind the parameters. Sounds like you're hitting the page twice. Check for missing image, css files, favicons, js files etc. -- hype WWW: plphp.dk / plind.dk LinkedIn: plind BeWelcome/Couchsurfing: Fake51 Twitter: kafe15 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Add +1 mysql updates by 2?
I took that into consideration so I added the update at the very end of document... Still the same, RD On Nov 27, 2010, at 12:31 AM, Peter Lind wrote: On Saturday, November 27, 2010, Richard West p...@cbnisp.com wrote: Hey Tommy, I get the same when seting it to a_downloads=a_downloads+1 It still increments by 2 I've never run into this before. RD On Nov 26, 2010, at 11:45 PM, Tommy Pham wrote: -Original Message- From: Tamara Temple [mailto:tamouse.li...@gmail.com] Sent: Friday, November 26, 2010 7:54 PM To: Richard West Cc: PHP General Mailing List Subject: Re: [PHP] PHP Add +1 mysql updates by 2? On Nov 26, 2010, at 8:36 PM, Richard West wrote: Hey guys, I've never run into this before. I have a field in mysql for page views. So I pull out value and do +1 to new value - after UPDATE SET it has incremented by 2? $val = $row['a_downloads'] ; $new_val = $val+1; mysql_query(UPDATE cbn_articles SET a_downloads='$new_val' WHERE a_id = '.$_GET['id'].' ); Any ideas? What am I missing? RD a_downloads wouldn't happen to be an autoincrement value, would it? IIRC, the auto_increment should only increment on an INSERT statement and the field is omitted. Besides, in MySQL, auto_increment must also be part of the primary key. From Richard's query, I'd say that his primary key field is most likely a_id. IMO, the best way to count something is to set the field to an int(eger) type. Then just run 'UPDATE table_name SET count_field = count_field +1 WHERE criteria_column = $criteria'. This is more safe as you many have simultaneous users downloading. This would ensure an accurate count, whereas your logic wouldn't. Regards, Tommy PS: Richard, you should validate and sanitize all inputs. Your query is prone to injection attack (deletion of rows or your entire DB deleted). Use either mysql_escape_string or, better yet, mysqli to prepare the statement and bind the parameters. Sounds like you're hitting the page twice. Check for missing image, css files, favicons, js files etc. -- hype WWW: plphp.dk / plind.dk LinkedIn: plind BeWelcome/Couchsurfing: Fake51 Twitter: kafe15 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Add +1 mysql updates by 2?
And what difference will that make if the document is requested twice with every browser load? On Nov 27, 2010 6:39 AM, Richard West p...@cbnisp.com wrote: I took that into consideration so I added the update at the very end of document... Still the same, RD On Nov 27, 2010, at 12:31 AM, Peter Lind wrote: On Saturday, November 27, 2010, Richard West p...@cbnisp.com wrote: Hey Tommy, I get the same when seting it to a_downloads=a_downloads+1 It still increments by 2 I've never run into this before. RD On Nov 26, 2010, at 11:45 PM, Tommy Pham wrote: -Original Message- From: Tamara Temple [mailto:tamouse.li...@gmail.com] Sent: Friday, November 26, 2010 7:54 PM To: Richard West Cc: PHP General Mailing List Subject: Re: [PHP] PHP Add +1 mysql updates by 2? On Nov 26, 2010, at 8:36 PM, Richard West wrote: Hey guys, I've never run into this before. I have a field in mysql for page views. So I pull out value and do +1 to new value - after UPDATE SET it has incremented by 2? $val = $row['a_downloads'] ; $new_val = $val+1; mysql_query(UPDATE cbn_articles SET a_downloads='$new_val' WHERE a_id = '.$_GET['id'].' ); Any ideas? What am I missing? RD a_downloads wouldn't happen to be an autoincrement value, would it? IIRC, the auto_increment should only increment on an INSERT statement and the field is omitted. Besides, in MySQL, auto_increment must also be part of the primary key. From Richard's query, I'd say that his primary key field is most likely a_id. IMO, the best way to count something is to set the field to an int(eger) type. Then just run 'UPDATE table_name SET count_field = count_field +1 WHERE criteria_column = $criteria'. This is more safe as you many have simultaneous users downloading. This would ensure an accurate count, whereas your logic wouldn't. Regards, Tommy PS: Richard, you should validate and sanitize all inputs. Your query is prone to injection attack (deletion of rows or your entire DB deleted). Use either mysql_escape_string or, better yet, mysqli to prepare the statement and bind the parameters. Sounds like you're hitting the page twice. Check for missing image, css files, favicons, js files etc. -- hype WWW: plphp.dk / plind.dk LinkedIn: plind BeWelcome/Couchsurfing: Fake51 Twitter: kafe15 /hype
RE: [PHP] PHP Add +1 mysql updates by 2?
-Original Message- From: Richard West [mailto:p...@cbnisp.com] Sent: Friday, November 26, 2010 9:40 PM To: Peter Lind Cc: Tommy Pham; Tamara Temple; PHP General Mailing List Subject: Re: [PHP] PHP Add +1 mysql updates by 2? I took that into consideration so I added the update at the very end of document... Still the same, RD snip Things to consider as part of your application design/flow: 1) Are you doing all PHP processing (application initialization, DB retrieval, user preference settings, etc.) before any header, echo, print, printf, output buffer, etc... ? At which point is the update done? 2) Are you sure the DB update is only called for or included/required once for that particular URL request? 3) Do you any have other page (js - or in page ajax calls, css, php, html, etc) that requests the page (with the update) again, as Peter mentioned? It will help you if you do an UML or a flow chart of the application flow. Regards, Tommy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php