Re: PHP Add +1 mysql updates by 2?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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" <php@xxxxxxxxxx> 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 <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>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux