title: Function to Make Empty String NULL for MySQL Insertion in PHP
body: <p>This is similar question to <a href="https://stackoverflow.com/questions/4620391/mysql-and-php-insert-null-rather-than-empty-string">MySQL and PHP - insert NULL rather than empty string</a> but I'm still encountering the problem.</p>
  
  <p>I'm trying to create a function so that an empty string is inserted as a NULL into MySQL.</p>
  
  <p>I create the function IsEmptyString:</p>
  
  <pre><code>function IsEmptyString($val){
      if (trim($val) === ''){$val = "NULL";}
  }
  </code></pre>
  
  <p>Before inserting the the variable, I escape it and then I call the function above. I've also tried <code>$val = NULL;</code></p>
  
  <p>What am I doing wrong? Also should I call the function before escaping?</p>