VVV
VVV

Reputation: 417

UPDATE concat and variables

I might just be sleepy, but i've tried to concat this in various ways and it just isn't working. the $friend_id is simply a string, and shouldn't be causing a problem as far as I know.

mysql_query("UPDATE users SET friends =  CONCAT(friends,"$friend_id")  WHERE username = '$user_logged_in'") or die mysql_error());

or

mysql_query("UPDATE users SET friends = friends +" . ", " . "'$friend_id' WHERE username = '$user_logged_in'");

any ideas where im tripping up?

Upvotes: 0

Views: 4713

Answers (4)

kwelsan
kwelsan

Reputation: 1219

Before run the query please check your variable "$friend_id". I just trimmed ",".

$friend_id = trim($friend_id, ',');

Query:

mysql_query("UPDATE users SET friends =  CONCAT(friends,'".$friend_id."')  WHERE username = '".$user_logged_in."'") or die mysql_error());

Upvotes: 0

VVV
VVV

Reputation: 417

This is what worked in the end.

mysql_query("UPDATE users SET friends = CONCAT(friends,'".",".$friend_id."') WHERE username = '$user_logged_in'");

Upvotes: 2

Francois
Francois

Reputation: 10978

Use . to concat string in PHP.

mysql_query("UPDATE users SET friends =  CONCAT(friends,".$friend_id.")  WHERE username = '$user_logged_in'") or die mysql_error());

Upvotes: 0

Bunjerd Sparrow
Bunjerd Sparrow

Reputation: 88

try this

mysql_query("UPDATE users SET friends =  CONCAT(friends,'".$friend_id."')  WHERE username = '".$user_logged_in."'") or die mysql_error());

Upvotes: 1

Related Questions