once again I have a question for hivemind STACKOVERFLOW. Here's the deal, I'm trying to insert all my $ _POST data from a form into a mysql table. I used to do:
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 $ values ββwere declared as $ _POST ['Place'], $ _POST ['Date'], etc. Now, every time I add a new form to the form (for example, a different text area or something else), I just want to create a new column in mysql instead of adding another $ _POST ['foo']. Here is what I tried to do:
// 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 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 get is: The number of columns does not match the number of values ββin row 1. I understand that this means that I am trying to put too much data in the database because there are not enough columns for the data. I checked back and forth to see if I was right (which, I think, is). For reference, here is my code for mysql form and 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 | watch | comments | howdiditgo | description | studentleader_name | studentleader_email | Username
NOTE. I also plan to sanitize my DB / $ POST data, but for my own purposes I left it! If you have any questions, feel free to ask and I will post here with EDIT: tags :)