views:

34

answers:

2

HEllo guys,

I am having an issue that is anoing me. I have a very simple table (MyISAM) where i have a field "count(INT)(11)"

It's just a counter that's increment every time one product/item is viewed. The problem is that query is incrementing 2 and not 1.

Ie. Actualfield value = 10

than i run: mysql_query("update table_test set count = count+1 where id = 1");

the field count value goes to 12 and not to 11.

I thought maybe my script is runnig 2x the query, then i've done a clean file with this lines:


    $con = mysql_connect("localhot","user","pass");
    mysql_select_db("database");
    mysql_query("update table_test set count = count+1 where id = 1");

and nothing more in the file .. it still add 2 insted 1. but if i copy this query and run using Phpmyadmin it work.

Any have idea of what happening?

Thanx very much Kid regards Tarsis Florencio

This is the full code i am using:


include 'includes/constants.php'; //just db_user, db_pass and connection
include 'includes/connect.php';

//here i select the actual count value
$result = mysql_query("select count from pictures where id = 6909") or die (mysql_error()." - [select count from pictures where id = 6909]");
$row = mysql_fetch_array($result);
$aux = (int)$row['viewed'] + 1; // increment
mysql_query("UPDATE pictures SET viewed = {$aux} WHERE id = 6909");

Also i've try:


mysql_query("UPDATE pictures SET viewed = viewed+1 WHERE id = 6909");

If i run the file using the query like this: UPDATE pictures SET viewed = 15 WHERE id = 6909

where i specify the value to be updated, works.

A: 

If you are including the same query in phpMyAdmin and it is working, it is not a problem with your query, Can you share the code you are calling the query from?

b8b8j
A: 

ive had a lot of problems with especially early firefox version loading pages twice if they needed to clear buffers :( that lead to a lot of confusing errors.

Android Noob
Hi there, you right. i try on IE and it is fine. The probem is with FireFox. What a shame. I am using the latest FF version with FireBug add-on. I clean the cache, history, etc, but still the same. Thanks for you answer.
Varois
we started using commandline php to avoid this problem :)
Android Noob