Reputation: 1068
Its a strange problem that I am having. I am trying to update a value in the database table with a new one by concatenating old and new values with a comma in between. So basically my value now is: Hello and I am updating it to World and I want the new value to be Hello,world but I am unable to do this. Both the CONCAT and CONCAT_WS functions through an error that you have invalid syntax.
Table name is fields. The column I wish to update is values and the new value to be concatenated is $newval. Here is my query.
$sql="update fields set values=CONCAT_WS(',',values, '$newval') where name='fundType'";
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 'values=CONCAT_WS(',',values, 'Buyout') where name='fundType'' at line 1
Any help will be appreciated. Ahmar A.
Upvotes: 1
Views: 1113
Reputation: 5337
values
is a keyword of mysql. use backticks ``
to mark it as a field name:
$sql="update fields set `values`=CONCAT_WS(',',`values`, '$newval') where name='fundType'";
Upvotes: 3