0

I'm working on a mailbox system for a game on Facebook. I have 2 inputs to a php script, with example input below:

$FriendIDs = "10000001,10002421,10132000,10074794,13523543"

$MailCode = "ReqGem"

and a table with the columns ID, Mailbox.

What I want to be able to do is concatenate whatever was originally in the Mailbox field, with MailCode, for each person in the FriendIDs.

I figured it was something like this, but I couldn't get it to work (my php/sql knowledge is pretty dire!):

mysqli_query($db, "UPDATE Save SET Mailbox = CONCAT(Mailbox,'$MailCode' . '_') WHERE 'id' IN $FriendIDs);

EDIT: I've just realized I need to add a new row if the FriendID isn't already in the table.

I'm guessing I need to start out with INSERT INTO and then use ON DUPLICATE KEY UPDATE, but I can't seem to get it to work. It's a bit trickier since the unique key is in an array, and I can't use WHERE id IN(ArrayOfValues) in an INSERT query.

Any help would be greatly appreciated!

1 Answer 1

2

You're close:

$FriendIDs = "10000001,10002421,10132000,10074794,13523543";
$MailCode = "ReqGem";
mysqli_query($db, "UPDATE Save SET Mailbox = CONCAT(Mailbox,'$MailCode' . '_') WHERE `id` IN($FriendIDs));
  • You just needed the parenthesis for IN() as it is a function.
  • Don't use single quotes for column names. Use ticks. Single quotes are for strings.
Sign up to request clarification or add additional context in comments.

1 Comment

Much appreciated. The subtle difference between the tick and the single quote keeps making me slip up!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.