title: Insert All Post Data into MySQL Database
body: <p>The following topic is close to what I'm trying to ask, but it's outdated considering the mysql functions are deprecated in php now and there are prepared statements for preventing sql injection. <a href="https://stackoverflow.com/questions/3338138/insert-all-post-data-into-mysql-using-php">insert all $_POST data into mysql using PHP?</a></p>
  
  <p>Basically, I have a huge number of columns in my database that all need to get filled up when I submit this form.  The form matches each column with an input field of the same name (the name attribute on the input field is the same as the column name it belongs in. So <code>$_POST['firstName']</code> goes in the <code>firstName</code> column, and so on).</p>
  
  <p>Is there a way using mysqli or PDO that I could easily just take all my POST data and automatically insert it into the MySQL table without going through each field by hand?  I could code them all out using prepared statements, but there are a ton of columns and I'd like to get them done all at once if possible.</p>
  
  <p>This is the beginning of the long version I don't really want to have to complete.</p>
  
  <pre><code>$stmt = $connection-&gt;prepare("INSERT INTO area_retreat 
  (user,firstName,lastName,...etc) 
  VALUES 
  (?,?,?,...etc)
  ON DUPLICATE KEY UPDATE 
  user=VALUES(user),
  firstName=VALUES(firstName),
  lastName=VALUES(lastName),
  ...etc
  ");
  $stmt-&gt;bind_param("sss",
      $username,
      $_POST['firstName'],
      $_POST['lastName']
   );
  
  $stmt-&gt;execute();
  </code></pre>