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.
Incrementing data
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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.
Hope this helps,
Mac
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'";Mac
All good now
thanks man its all working good now, I never realised about these reserved words
.. That could solve a few probs