SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    storing submitted information in the database.

    I have a website with about 100 different subjects.
    each subject has a form with different fields for the user to fill.

    The information filled is being sent to a specific mail and only fields that exists in every subject, like 'name, age, email' are being stored in the database.

    Now i want to store the other fields in the database as well.
    I can just create a new column in the database for each of those fields but it's a bad solution because i'll have to change the code and add a db column manually for any new field.

    What else can i do if i want to add an option in the administration panel
    for adding new fields and having it stored in the database when the
    form is submitted for statistics etc..

    thanks in advance and sorry for my English.

  2. #2
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    586
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by elme View Post
    Now i want to store the other fields in the database as well.
    but it's a bad solution creating a new column in the database for each of those fields because i'll have to change the code and add a db column manually
    for any new field.
    How else can you do that if you don't change codes and how else can you store other info if you don't add a db column. Well you can write it to a text file.
    Don't Panic

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stonedeft View Post
    How else can you do that if you don't change codes and how else can you store other info if you don't add a db column. Well you can write it to a text file.
    I built the website for someone else and he controls it using the admin panel.
    the problem with adding a new field and having it saved in the database for statistics
    is that he needs me each time he wants to add a new field.

    I can use XML, but can an XML file hold information of thousands submitted forms?

  4. #4
    SitePoint Guru
    Join Date
    Nov 2003
    Location
    Huntsville AL
    Posts
    689
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Yes, xml can hold thousands of records.

    But it sounds like you want custom defined columns without changing the database schema. You can do this with a schema that looks something like this:

    ; Start with table holding your records with predefined columns
    record
    ..int record_id
    ..char name
    ..int age
    ..char email

    ; This table holds the custom column information
    custom_column
    ..int record_id
    ..char column_name
    ..char column_value

    ; And you probably want a third table to define the custom columns
    custom_column_definition
    ..char column_name
    ..char column_desc

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Sounds as if this could be heading the way of an EAV discussion, here's one from earlier this year ; Modeling product attributes/options.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •