title: insert all $_POST data into mysql using PHP?
body: <p>once again I have a question for the STACKOVERFLOW hivemind.  Here's the deal, I'm trying to insert all of my $_POST data from a form into a mysql table.  Before, I did:</p>
  
  <pre><code>    INSERT INTO forms (Place, Date, Find, username, who_sponsored, hours, comments, howdiditgo, studentleader_name, studentleader_email, description)
  VALUES ('$place', '$date','$where', '$username', '$who', '$hours', '$comments', '$how', '$description',)");
  </code></pre>
  
  <p>where all the $values were declared as $_POST['Place'], $_POST['Date'], etc.  Now, every time I add a new part to the form (like another textarea or something), I want to just have to create a new column in mysql instead of adding another $_POST['foo'].  Here's what I have tried doing:</p>
  
  <pre><code>// In the previous form, I have set all input ids to "service[]", so all this data would be in a more specific array than just $POST.  Turns out all the $_POST['service'] stuff is null...  Here's an example: &lt;input name="placeofservice" type="text" id="service[]"&gt;
  
  
  $forms = serialize($_POST['service']);
  var_dump($forms);
  
  mysql_query("INSERT INTO forms VALUES('$forms')")
   or die(mysql_error()); 
  </code></pre>
  
  <p>The error I keep receiving is: Column count doesn't match value count at row 1.  I realize this means that I am trying to put too much data into the database, because there are not enough columns to fit the data.  I've checked back and forth to see if I have it right (which, I think I do).  For Reference, here's my code for both the form and mysql table:</p>
  
  <pre><code>&lt;form name="form1" method="post" action="process_form.php"&gt;
  Place of Service&lt;/br&gt;
  &lt;input name="placeofservice" type="text" id="service[]"&gt;&lt;/br&gt;
  
  Date of Service&lt;/br&gt;
  &lt;input name="dateofservice" type="text" id="service[]"&gt;&lt;/br&gt;
  
  Where did you find this opportunity?&lt;/br&gt;
  &lt;input name="where" type="text" id="service[]"&gt;&lt;/br&gt;
  
  What organization sponsored this opportunity?&lt;/br&gt;
  &lt;input name="who_sponsored" type="text" id="service[]"&gt;&lt;/br&gt;
  
  How many hours did you work?&lt;/br&gt;
  &lt;input name="hours" type="text" id="service[]"&gt;&lt;/br&gt;
  
  How did it go?&lt;/br&gt;
  &lt;input type="text" id="service[]" name="howdiditgo" maxlength="100" /&gt;&lt;/br&gt;
  
  Description of Service:
  &lt;textarea name="description" id="service[]" COLS=40 ROWS=6&gt;&lt;/textarea&gt;&lt;/br&gt;
  
  Comments:
  &lt;textarea name="comments" id="service[]" COLS=40 ROWS=6&gt;&lt;/textarea&gt;&lt;/br&gt;
  
  Student Leader Name (If Applicable)&lt;/br&gt;
  &lt;input name="studentleader_name" type="text" id="service[]"&gt;&lt;/br&gt;
  
  Student Leader Email(If Applicable)&lt;/br&gt;
  &lt;input name="studentleader_email" type="text" id="service[]"&gt;&lt;/br&gt;
  &lt;input type="submit" name="Submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Mysql Table:</p>
  
  <p>Place | Date | Find |form_id | who_sponsored | hours | comments | howdiditgo  | description | studentleader_name | studentleader_email | username</p>
  
  <p>NOTE:  I plan to sanitize my DB contents/$POST data as well, but for my purposes I left it out!  If you have any questions feel free to ask and I'll post here with EDIT: tags :)</p>