On Saturday, November 27, 2010, Richard West <php@xxxxxxxxxx> 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.lists@xxxxxxxxx] >>> Sent: Friday, November 26, 2010 7:54 PM >>> To: Richard West >>> Cc: PHP General Mailing List >>> Subject: Re: 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