views:

40

answers:

1

See something wrong in my code? I can't get the update function to work.. weird thing is the rest works correctly, and the same code works 100% on another page.

<?php
include("config.php");

$id = $_GET['id'];

$number = $_GET['no'];

$result = mysql_query("SELECT * FROM comments WHERE commentid = '$id'")
or die(mysql_error());  

$row = mysql_fetch_array( $result );

mysql_query("update `comments` set like = like +1 where commentid = '$id'"); <--- only this here doesnt work
?>

And there is 1 line of html after that, a span tag getting some information out of the comments table. My 'like' column is set to int(11), so I don't see that being the problem.

Hope this isnt another innatention mistake :/

Thanks alot to anyone who can help me out!

This is the error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'like = like +1 where commentid = '61'' at line 1

+2  A: 

As EboMike posted, LIKE is a reserved keyword in MySQL.

You can either rename your column to something else that is not a keyword (preferred), or you can put a backtick (a backwards single quote) around it to tell MySQL it's a literal name.

Cyntech
Not single quotes, but backticks.
BoltClock
I've tried both in phpMyAdmin and they both work. I'll update my answer all the same. Thanks.
Cyntech
Rename your column. Quoting it will work, but it'll cause you more pain later. Just rename it.
Steven Schlansker
While you are at it, trying to make sure you sanitize your inputs before placing them into a SQL query. This is how SQL injection attacks occur.
Aduljr