Connecting Tech Pros Worldwide Forums | Help | Site Map

Form submission

Newbie
 
Join Date: Sep 2009
Posts: 18
#1: Oct 7 '09
If I have a form with 50-200 input fields, how can I submit them as one PHP/MYSQL insert command?

Ex. Form has input fields of: Lastname, Firstname, SS#, favorite color.
How can I submit all of these/consolidate into a MYSQL table with field name Personalinfo?

Thank you in advance,
MO
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,747
#2: Oct 7 '09

re: Form submission


Hey.

You want to insert the data form 50-200 form input fields into a single field in a MySQL table?!
You never put more than a single piece of data into a single field. It's the first, and most important, rule of database design.

If you need to store 50-200 pieces of personal info on your users, you either create a single table that has 200 columns, one for each possible piece of data (not every field has to be filled for each row), or you create a "dynamic" table, where you just store a key/value pair, filling in each as you go.

Example of the first option: (very basic)
Expand|Select|Wrap|Line Numbers
  1. +----+-----------+-----------+----------+---------------+--------+
  2. | id | ss_number | firstname | lastname | favorit_color | etc... |
  3. +----+-----------+-----------+----------+---------------+--------+
  4. |  1 | 11111111  | John      | Doe      | Blue          | ...    |
  5. |  2 | NULL      | Jane      | Doe      | Red           | ...    |
  6. +----+-----------+-----------+----------+---------------+--------+
(Note the NULL for the second row's ss_number field. Indicates that there was no value provided for that field.)

Example of the second option:
Expand|Select|Wrap|Line Numbers
  1. +----+-----------+----------+
  2. | id | firstname | lastname |
  3. +----+-----------+----------+
  4. |  1 | John      | Doe      |
  5. |  2 | Jane      | Doe      |
  6. +----+-----------+----------+
  7. +----+---------+---------------+-----------+
  8. | id | user_id | key           | value     |
  9. +----+---------+---------------+-----------+
  10. |  1 |       1 | favorit_color | Blue      |
  11. |  2 |       1 | ss_number     | 11111111  |
  12. |  3 |       2 | favorit_color | Red       |
  13. +----+---------+---------------+-----------+
(Here, the absence of the second user's ss_number just means that it is not inserted into the key/value table.)
Reply