Sasha
Sasha

Reputation: 8705

Codeigniter 2.1 - MySQL CONCAT (append string)

I have PHP code like this:

$query = 'UPDATE  `user_vote` SET `container` = CONCAT(`container`, ' ;
$query .=  ",$glas";
$query .= ') WHERE `user_id` = ' . $id_u;
$this->db->query($query);

When I run this code, I got following error:

Error Number: 1054

Unknown column ',iljadu' in 'field list'

UPDATE user_vote SET container = CONCAT(container, ,iljadu) WHERE user_id = 4

What is wrong with the query?

Upvotes: 0

Views: 2356

Answers (2)

Fluffeh
Fluffeh

Reputation: 33512

You are missing quotes around your variable for the concat()

$query = 'UPDATE  `user_vote` SET `container` = CONCAT(`container`, ' ;
$query .=  ",'$glas'";
$query .= ') WHERE `user_id` = ' . $id_u;
$this->db->query($query);

Upvotes: 4

Laurence
Laurence

Reputation: 60048

$query .=  ",$glas";

should be

$query .=  "$glas";

Upvotes: 1

Related Questions