Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL issue with UPDATE numbers [duplicate]

Tags:

php

mysql

I'm trying to do a very simple UPDATE with PHP, like this:

$nlk = $lk + "1";
mysql_query("UPDATE posts SET like = '".$nlk."' WHERE id = '".$cid."'") or die(mysql_error());

$lk is a the value gotten from the field like, which is default 0. $cid is a value from an id field, which is on auto_increment.

I get this 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 = '1' WHERE id = '45'' at line 1

What is the issue here?

like image 649
Deniz Zoeteman Avatar asked Nov 30 '25 01:11

Deniz Zoeteman


1 Answers

like is a reserved word. You need to surround it with back-ticks

mysql_query("UPDATE posts SET `like` = '".$nlk."' WHERE id = '".$cid."'") or die(mysql_error());
like image 53
sreimer Avatar answered Dec 02 '25 13:12

sreimer