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());

Recommended Answers

Use MySQL's CONCAT() function

To add data at the end of existing

mysql_query("UPDATE stk SET some_field = CONCAT(some_field, '????????????') WHERE id = " . $upc_key . "") or die(mysql_error());
Jump to Post

All 2 Replies

Use MySQL's CONCAT() function

To add data at the end of existing

mysql_query("UPDATE stk SET some_field = CONCAT(some_field, '????????????') WHERE id = " . $upc_key . "") or die(mysql_error());

To add data at the start of existing

mysql_query("UPDATE stk SET some_field = CONCAT('????????????',some_field) WHERE id = " . $upc_key . "") or die(mysql_error());

That worked. Just needed to escape the double quotes.

Thanks mwasif.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.