title: mysqli_real_escape_string deleting values
body: <p>I'm getting null values after I run the DBEscape($data) function that is for SQL injection protection. Can someone help?</p>
  
  <p>My inputs are all multiple arrays, ex: name="quote[][dt_flight]", name="quote[][acft]", etc.</p>
  
  <p>Method is POST.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>function DBEscape($data){
      $link = DBConect();
      if(!is_array($data)){
          $data = mysqli_real_escape_string($link,$data);
      }
      else {
          $arr = $data;
          foreach ($arr as $key =&gt; $value){
              $key = mysqli_real_escape_string($link, $key);
              $value = mysqli_real_escape_string($link, $value);
              $data[$key] = $value;
          }
      }
      DBClose($link);
      return $data;
  }
  
  
  
      function DBCreate($table, array $data, $insertId = false){
          $table = DB_PREFIX.'_'.$table;
          $data = DBEscape($data);
          var_dump($data);
          $fields = implode(", ", array_keys($data));
          $values = "'".implode("', '", $data)."'";
          $query = "INSERT INTO {$table} ({$fields}) VALUES ({$values});";
          var_dump($query);
          return DBExecute($query, $insertId);
      }
  
  
  if(isset($_POST["quote"]) &amp;&amp; is_array($_POST["quote"])){
      foreach($_POST["quote"]["dt_flight"] as $key =&gt; $text_field){
          
          $last_id = DBCreate('quote',$_POST['quote'],true);
         
         $i++;
      }  
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>The connection works since it is inserting the rows into the tables. I used vardump before and after the DBEscape to figure out that it is deleting the values, the keys are fine.</p>
  
  <p>PS: The proposed answer is for a single variable not an array.</p>