title: double post entry into db while using function?
body: <p>hello i have a problem using a function to insert user data into a db. the query will be executed twice and i have no clue why this is happening.</p>
  
  <p>i do use this code:</p>
  
  <p>if (empty($_POST['submit']) === false &amp;&amp; empty($errors) === true) { </p>
  
  <pre><code>$random = substr(str_shuffle('./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 22);;
  
  $timezone = 'Europe/Berlin';
  date_default_timezone_set($timezone);
  $timestamp = time();
  $time = date("d.m.Y - H:i:s", $timestamp);
  
  $register_data = array(
      'a'     =&gt; $_POST['a'],
      'b'     =&gt; $_POST['b'],
      'c'     =&gt; $_POST['c'],
      'd'     =&gt; $_POST['d'],
      'e'     =&gt; $_POST['e'],
      'f'     =&gt; md5($_POST['password']),
      'g'     =&gt; md5($random),
      'h' =&gt; $time,
  );
  register_user($register_data);
  
  if (register_user($register_data) === true) {
      echo "done";
  }   
  exit();
  </code></pre>
  
  <p>}</p>
  
  <p>and the functions are:</p>
  
  <pre><code>function array_sanitize(&amp;$item){
      global $db;
      return mysqli_real_escape_string($db, $item);
  }
  
  function register_user($register_data){
      global $db;
      array_walk($register_data, 'array_sanitize');
  
      $fields = '`' . implode('`, `', array_keys($register_data)) . '`';
      $data = '\'' . implode('\', \'', $register_data) . '\'';
  
      $insert = $db-&gt;query("INSERT INTO `table1` ($fields) VALUES ($data) "); 
      return (true);
  }
  </code></pre>
  
  <p>but when replacing this function:</p>
  
  <pre><code>function register_user($register_data){
      global $db;
      array_walk($register_data, 'array_sanitize');
  
      $fields = '`' . implode('`, `', array_keys($register_data)) . '`';
      $data = '\'' . implode('\', \'', $register_data) . '\'';
  
      $sql = "INSERT INTO `table1` ($fields) VALUES(?,?,?,?,?,?,?,NOW())";
          if($query = $db-&gt;prepare($sql)){
              $query-&gt;bind_param('sssssss', $data);
              $query-&gt;execute();
  
              if ($query-&gt;affected_rows == 1) {
                  echo 'success';
              } else {
                  echo 'nope';
              }
          }
  
      return (true);
  }
  </code></pre>
  
  <p>and removing the last key from the array $register_data does not work at all.</p>
  
  <p>it would be great if someone could help me out.</p>
  
  <p>thanks alot.</p>