user2413763
user2413763

Reputation: 81

PHP - Issue update db field with add to existing value

I have db field say like this : For example, lets say we have table like this

    +--------------+
    | some_table   |
    +--------------+
    | name  | text |
    +--------------+
    |  a    | b    |
    +--------------+

I want to update without delete existing value. say i want to update field name and text with adding " add" , so value of field now is b add

I try use query : mysql_query("update table set text=text+' add' where name='a' ");

Can you analyze this issue?

Thanks in advance.

Upvotes: 1

Views: 318

Answers (3)

Joshua Burns
Joshua Burns

Reputation: 8572

Using the CONCAT() method:

UPDATE table SET text = CONCAT(text, ' add') WHERE name = 'a'

The following should also work:

UPDATE table SET text = text ' add' WHERE name = 'a'

Upvotes: 1

Iswanto San
Iswanto San

Reputation: 18569

Try to use MySQL CONCAT function

mysql_query("update table set text=concat(text, ' add') where name='a' ");

Upvotes: 0

Michael Krikorev
Michael Krikorev

Reputation: 2156

COncatenate strings with CONCAT function:

mysql_query("update table set text = CONCAT(text, ' add') where name='a' ");

Upvotes: 1

Related Questions