greenpool
greenpool

Reputation: 561

PHP/MySQL Concat to a single column and Update other columns in table

Am trying to only concat new updates to column updates and UPDATE the values in the rest of the columns but I've hit bit of a snag that I can't seem to workout.

My SQL looks like this:

$query="Update tickets SET product='$product',
        p='$p',
        i='$i',
        summary='$summary',
        workaround='$workaround',
        concat(updates,'$additional_update'),
        status='$status',
        raised_by='$raised_by',
        updated_by_user='$updated_by' WHERE id='$id'";

the updates column is like a comments column, where new updates are meant to be appended to the existing text.

The error I'm getting on the web server:

Update tickets SET product='T-Box', p='00000817766', i='-', summary='Testing update field
\r\nAdding an update\r\ntesting if null works for update', workaround='n/a', concat(updates,' ','test2@18:53:17:second update/n'), status='Open', raised_by='No', updated_by_user='test2' WHERE id='223'

Running the query directly in MySQL:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(updates,'test2@18:53:17:second update/n'), status='Open', raised_by='No', updat' at line 1

Help is much appreciated!

Upvotes: 0

Views: 231

Answers (2)

John Woo
John Woo

Reputation: 263693

You need to specify where the value of this statement concat(updates,'$additional_update') to be set.

Update tickets 
SET    product = '$product',
       p = '$p',
       i = '$i',
       summary = '$summary',
       workaround = '$workaround',
       updates = CONCAT(updates,'$additional_update'),  // <== see this
       status = '$status',
       raised_by = '$raised_by',
       updated_by_user = '$updated_by' 
WHERE id = '$id'

Upvotes: 2

AnandPhadke
AnandPhadke

Reputation: 13486

try this:

$query="Update tickets SET product='$product',
        p='$p',
        i='$i',
        summary='$summary',
        workaround='$workaround',
        updates=concat(updates,'$additional_update'),
        status='$status',
        raised_by='$raised_by',
        updated_by_user='$updated_by' WHERE id='$id'";

Upvotes: 0

Related Questions