title: mysqli_real_escape_string and stripslashes returning blank variables
body: <p>I am using the following code to clean any variables that get returned from forms. I recently swapped over from mysql to mysqli but as a result the function below is now stripping my variables back to being blank.</p>
  
  <pre><code>//Start session
  session_start();
  
  //Include database connection details
  require_once('config.php');
  
  //Array to store validation errors
  $errmsg_arr = array();
  
  //Validation error flag
  $errflag = false;
  
  //Connect to mysql server
  $link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
  if(!$link) {
      die('Failed to connect to server: ' . mysqli_error());
  }
  
  //Select database
  $db = mysqli_select_db($link,DB_DATABASE);
  if(!$db) {
      die("Unable to select database");
  }
  
  //Function to sanitize values received from the form. Prevents SQL injection
  function clean($str) {
      $str = @trim($str);
      if(get_magic_quotes_gpc()) {
          $str = stripslashes($str);
      }
      return mysqli_real_escape_string($link,$str);
  }
  
  //Sanitize the POST values
  $login = clean($_POST['login']);
  $password = clean($_POST['password']);
  
  //Input Validations
  if($login == '') {
      $errmsg_arr[] = 'Login ID missing';
      $errflag = true;
  }
  if($password == '') {
      $errmsg_arr[] = 'Password missing';
      $errflag = true;
  }
  
  //If there are input validations, redirect back to the login form
  if($errflag) {
      $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
      session_write_close();
      header("location: login-form.php");
      exit();
  }
  </code></pre>
  
  <p>So every time I type in a valid username and password it redirects me back to the login page saying that both fields were in fact blank. The moment I remove the 'clean' function around the POST values it starts working again.</p>
  
  <p>I'm new to mysqli however I can't see what I'm doing wrong. Can anyone help?</p>
  
  <p>Thanks</p>