Add to existing data with a variable

What’s the notation to add data from a variable to existing data in a field?

mysql_query("UPDATE stk SET some_field = ‘???’ WHERE id = " . $upc_key . “”) or die(mysql_error());

You don’t mean as a new row do you?

Rather append, eg.
change “John” to “John Smythe” using the variable value “Smythe”

Querys can be written to do mathematical changes on numeric fields (eg. field_name+1), but as far as I know appending text to a text field will require “get - append - save”

i couldn’t figure out what the original question was, but based on your interpretation – appending text data to an existing column – that’s done exactly the same way as incrementing a numeric column value

“get - append - save” isn’t required for either of them :wink:

UPDATE … SET numcolumn = numcolumn + 1

UPDATE … SET textcolumn = CONCAT(textcolumn,‘foo’)

exactly. What would that code look like? I googled get append save mysql and didn’t get what I needed.

if $var = ‘foo’;

Wouldn’t it be?:

UPDATE … SET textcolumn = CONCAT(textcolumn," . $var . ")…

I’ve never had to use CONCAT but its nice to know its there if and when I do - thanks :slight_smile:

That looks about right to me, though you may need to add in spaces or other punctuation to keep it sane.

UPDATE … SET textcolumn = CONCAT(textcolumn,’ " . $var . " ')…

I forgot to escape the double quotes:

$sql = “UPDATE … SET textcolumn = CONCAT(textcolumn,/”.$str./“)”;

That works. Thanks for everyone’s help: Mittineague and r937!