title: function to sanitize input to Mysql database
body: <p>I am trying to put a general purpose function together that will sanitize input to a Mysql database. So far this is what I have:</p>
  
  <pre><code>function sanitize($input){
      if(get_magic_quotes_qpc($input)){
  
          $input = trim($input); // get rid of white space left and right
          $input = htmlentities($input); // convert symbols to html entities
          return $input;
      } else {
  
          $input = htmlentities($input); // convert symbols to html entities
          $input = addslashes($input); // server doesn't add slashes, so we will add them to escape ',",\,NULL
          $input = mysql_real_escape_string($input); // escapes \x00, \n, \r, \, ', " and \x1a
          return $input;
      }
  }
  </code></pre>
  
  <p>If i understood the definition of <code>get_magic_quotes_qpc()</code>. This is set by the php server to automatically escape characters instead of needing to use <code>addslashes()</code>.</p>
  
  <p>Have I used <code>addslashes()</code> and <code>mysql_real_escape_string()</code> correctly together and is there anything else I could add to increase the sanitization.</p>
  
  <p>Thanks</p>