Page 1 of 1

Incrementing data

Posted: Wed May 01, 2002 2:44 am
by pHaZed
Im creating a topsite list, With mysql for data.
but im having a probaly incrementing that hits in count.
i have a table called 'in', the table data is below
in int(7) NOT NULL default '0'
Here is the code i use to increment the data

$update= "UPDATE `topsites` SET `in` = 'in + 1' WHERE `id` = '$vote'";
$add_vote = mysql_db_query('netesp', $update, $mysql_link) or die(mysql_error());


the variable $vote... is defined in the url. eg http://bla.com/in.php?vote=1
were vote is the id of the site to add a vote to.
this is not working...
I tried updating it manually to 2 (without +1) and then try to execute the vote code. but it just sets it back to 0.
Any help much appreciated.

Posted: Wed May 01, 2002 7:13 am
by twigletmac
You can't have a column or table named 'in' because 'in' is a reserved name in MySQL.
http://www.mysql.com/doc/R/e/Reserved_words.html
You need to rename the column to something else eg. 'counts'.

The single quotes in your SQL statement are also causing issues, the UPDATE query doesn't need them:
http://www.mysql.com/doc/U/P/UPDATE.html
and I couldn't get the query to work with them, all it did was set 'counts' back to 0.

Code: Select all

$update= "UPDATE topsites SET counts=counts+1 WHERE id='$vote'";
Hope this helps,
Mac

All good now

Posted: Thu May 02, 2002 5:54 pm
by pHaZed
thanks man its all working good now, I never realised about these reserved words :? .. That could solve a few probs