title: How to prevent against XSS and SQL injection
body: <p>i want to check my data from the user for XSS and SQL injection and this is how i tried</p>
  
  <pre><code>if (isset($_GET['membernumber'])) 
  {
      $mem = htmlentities($_GET['membernumber']);
      $memberparamter = cleanData($mem);
  
  }
  </code></pre>
  
  <p>But which method is the best/correct way to check?</p>
  
  <p>Method 1</p>
  
  <pre><code>function cleanData($data)
      {
          $data=mysql_real_escape_string($data);
          $data=trim($data);
          $data=stripcslashes($data);
          $data=htmlspecialchars($data);
          $data=strip_tags($data);
          return $data;
      }
  </code></pre>
  
  <p>Method 2</p>
  
  <pre><code>function cleanData($data)
      {
          $data=mysql_real_escape_string($data);
          $data=trim($data);
          $data=strip_tags($data);
          return $data;
      }
  </code></pre>
  
  <p>Method3</p>
  
  <pre><code>htmlspecialchars(stripcslashes(trim($data)))
  </code></pre>