title: How can I improve this rustic way to insert info in mySQL with PHP?
body: <p>I would like to know better ways to improve or optimize this rustic way of adding contents to my mySQL database with PHP only if the variables are not empty.
  Thanks.</p>
  
  <pre><code>    &lt;?php
        $fields = "value_1, value_2, value_3, value_4";
        $contents = "'$value1','$value2', '$value3', '$value4'";
        if(!empty($value5)){
          $fields .= ", value_5";
          $contents .= ", '$value5'";
        }
        if(!empty($value6)){
          $fields .= ", value_6";
          $contents .= ", '$value6'";
        }
        $add =    "INSERT INTO love_table " . "(" . $fields . ")" . "VALUES (" . $contents . ")";
      ?&gt;
  </code></pre>