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:
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',)");
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:
// 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: <input name="placeofservice" type="text" id="service[]">
$forms = serialize($_POST['service']);
var_dump($forms);
mysql_query("INSERT INTO forms VALUES('$forms')")
or die(mysql_error());
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:
<form name="form1" method="post" action="process_form.php">
Place of Service</br>
<input name="placeofservice" type="text" id="service[]"></br>
Date of Service</br>
<input name="dateofservice" type="text" id="service[]"></br>
Where did you find this opportunity?</br>
<input name="where" type="text" id="service[]"></br>
What organization sponsored this opportunity?</br>
<input name="who_sponsored" type="text" id="service[]"></br>
How many hours did you work?</br>
<input name="hours" type="text" id="service[]"></br>
How did it go?</br>
<input type="text" id="service[]" name="howdiditgo" maxlength="100" /></br>
Description of Service:
<textarea name="description" id="service[]" COLS=40 ROWS=6></textarea></br>
Comments:
<textarea name="comments" id="service[]" COLS=40 ROWS=6></textarea></br>
Student Leader Name (If Applicable)</br>
<input name="studentleader_name" type="text" id="service[]"></br>
Student Leader Email(If Applicable)</br>
<input name="studentleader_email" type="text" id="service[]"></br>
<input type="submit" name="Submit" value="Submit">
</form>
Mysql Table:
Place | Date | Find |form_id | who_sponsored | hours | comments | howdiditgo | description | studentleader_name | studentleader_email | username
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 :)