brown.cn
brown.cn

Reputation: 151

mysql gives error when trying to update

My query was:

$query = "UPDATE shop.titem  SET 
item = $nitem, comment = $comment visible = $visible
WHERE titem.item =$item;";

And the error I get is:

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 'visible = 1 WHERE titem.item =lolipop' at line 2

I noticed that new version of MySQL doesn't really care about the hyphens so I chose to omit that. However, it gives me the same errors even though I use them for the variables. Help please.

Upvotes: 1

Views: 46

Answers (3)

NetStack
NetStack

Reputation: 208

Much better way to write the SQL query is :-

$query = "UPDATE shop.titem  SET item = '" . $nitem . "', comment = '" . $comment . "', visible = '" . $visible . "' WHERE titem.item = $item";

Also, I guess it should be shop.item instead of shop.titem.

Upvotes: 0

Nouphal.M
Nouphal.M

Reputation: 6344

You are missing a commaafter $comment and quotes around string value:

try

$query = "UPDATE shop.titem  SET 
item = '$nitem', comment = '$comment', visible = '$visible'
WHERE titem.item ='$item'";

Upvotes: 2

Adam
Adam

Reputation: 1694

Remove the semicolon after $item; inside the query and use '' for the string values

Upvotes: 0

Related Questions