简体   繁体   中英

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!

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'

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'";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM