title: how to check if values are null before entering into database?
body: <p>I have a php function</p>
  
  <pre><code>function insertIntoDb($db, $table) {
      mysql_select_db($db) or die("Could not select database. " . mysql_error());
      $resultInsert = mysql_query("SHOW COLUMNS FROM " . $table);
      $fieldnames=array();
        if (mysql_num_rows($resultInsert) &gt; 0) {
          while ($row = mysql_fetch_array($resultInsert)) {
              $fieldnames[] = $row['Field'];
              $values = array_intersect_key( $_POST, array_flip($fieldnames) ); #check if value is null otherwise do not INSERT
          }
        }
        $sql = sprintf('INSERT INTO %s (%s) VALUES ("%s")', $table, 
        implode(', ', array_map('mysql_escape_string', array_keys($values))), implode('", "',array_map('mysql_escape_string', $values))); 
        mysql_query($sql); 
        echo '&lt;div class="success"&gt;Data was entered into the database successfully!&lt;br&gt;&lt;a href="view.php?type=recent"&gt;View listing?&lt;/a&gt;&lt;/div&gt;';
  }
  </code></pre>
  
  <p>Basically I am using the table columns to generate fields for a user form, then using that same method to insert into the table. Currently it is working, however how do I check if the values being entered are empty (for example user hasnt filled out a field) before inserting it into the table?</p>