title: PHP PDO - Passing and imploded array to a query placeholder
body: <p>First of all, I apologize if this is answered somewhere else, but I couldn't find anything.</p>
  
  <p>I have problems with the following code:</p>
  
  <pre><code>function register_user ($register_data) {
      global $db;
      array_walk ($register_data, 'array_sanitize');
      $register_data ['password'] = md5 ($register_data ['password']); 
  
      $fields = '`' . implode ('`, `', array_keys ($register_data)) . '`';
      $data   = '\'' . implode ('\', \'', $register_data) . '\'';
  
      $query = $db -&gt; prepare ("INSERT INTO `users` (:fields) VALUES (:data)");
      $query -&gt; bindParam (':fields', $fields);
      $query -&gt; bindParam (':data', $data);
      $query -&gt; execute ();
  }
  </code></pre>
  
  <p>The problem is that this is executed correctly but the query is not ran and the row is not inserted in the database.</p>
  
  <p>Now, if I just do this:</p>
  
  <pre><code>$query = $db -&gt; prepare ("INSERT INTO `users` ($fields) VALUES ($data)");
  //$query -&gt; bindParam (':fields', $fields);
  //$query -&gt; bindParam (':data', $data);
  $query -&gt; execute ();
  </code></pre>
  
  <p>everything works like a charm, so I am guessing the problem is with how I am passing data to the placeholders.</p>
  
  <p>Can someone please explain to me why this is not working? I'd like to understand it properly in the first place.</p>
  
  <p>Thanks in advance for any help.</p>