php - concate the value into table if record is empty -


i updating record append new content same row. here query:

    $update1 = "update review_words set adjective = concat(adjective, ',', '$adjective'), noun = concat(noun, ',', '$noun') ";     if (!mysqli_query($con,$update1))     {     //  die('error: ' . mysqli_error($con));     //  echo "error";     } 

this works fine when there value in table. if table record empty not concate value.

can overcome issue?

use concat_ws() instead. that's you're looking for.

update review_words set adjective = concat_ws(',', adjective, '$adjective'),     noun = concat_ws(',', noun, '$noun') 

note you're vulnerable sql injection. please use mysqli or pdo parameterized queries avoid problem.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -