Results 1 to 5 of 5

Thread: Form Field & SQL questions

  1. #1
    Join Date
    Aug 2005

    Form Field & SQL questions

    I am preparing to try and write an application that will be using quite a few form fields to store user data. And I wanted to ask a few questions that I'm unsure about. The layout of the project will incorporate many pages in which the user will input data related to themselves. So my questions are:

    1) In my table setup for my DB(which is SQLServer) I want to use several tables, each that store diffrent sections of the data. I was thinking that using the sessionID might be useful as the PK and also for referencing the records. Any thoughts there?

    2) On my forms, I have a massive amount of fields. How do you go about setting it so that I can make it loop through all the fields on a particular page and only write the ones that are not Null? I.E. Some will be required fields which must be filled in, others will be optional.

    I'm thinking of setting up my tables like this:
    sessionid   varchar(50)   NOT NULL
    fieldname  varchar(50)
    fieldvalue  varchar(50)
    inputtime  timestamp(8)
    I was thinking that when the user submits thier form, that I could use a check by a SELECT statement to see if thier SessionID was in the DB, if not then I could use a INSERT to input thier data, otherwise I could simply use an UPDATE to alter whats thier, in case they make a mistake and need to go back.

    I am somewhat new at this, and am more or less looking for some feedback on how I might accomplish these tasks, as well as any other recommendation more experience developers may have.

    Thanks in advance.

  2. #2
    Join Date
    Jan 2003
    Dundee, Scotland
    answer to question 1 is yes, SessionID would be the Primary Key however you can set the datatype to auto that way every sessionID would be unique.

    question 2 you can loop through your form elements using this:

    for each item in requset.form
      'do something here.
      response.write "the item is: " & item
    or if you know the elements name then all you do is an if statement.

    if txtbox1 <> "" then
     response.write "insert into database"
    end if
    hope this helps

  3. #3
    Join Date
    Dec 2003
    England, UK
    are you talking about using the asp sessionId in your database?

    i would tend to avoid this unless you're only dealing with temporary data that doesn't matter once the session expires.

    in your case i would probably create a table like this

    create table person 
    id numeric(18,0) identity(1,1) not null,
    inserteddate datetime not null default(getdate()),
    deleted int not null default(0)
    and any other fields you might want (maybe a latest sessionid if you really want it?)
    and then the other table of possible fields like this

    create table personfield
    id numeric(18,0) identity(1,1) not null,
    name nvarchar(100) not null,
    deleted int not null default(0),
    inserteddate datetime not null default(getdate()),
    and then a final table linking the people and the fields

    create table linkpersonfieldperson
    id numeric(18,0) identity(1,1) not null,
    personfieldid numeric(18,0) not null,
    personid numeric(18,0) not null,
    value nvarchar(1000) not null,
    deleted int not null default(0),
    inserteddate datetime not null default(getdate()),
    so when you save someone you add a new person record and use its id when you add all the field data.

    does that make sense?

    it might be easier to write the form out as well if you've got the fields all in a table like this.

    this is almost exactly the same as this thread http://www.webdeveloper.com/forum/sh...d.php?t=120049

  4. #4
    Join Date
    Aug 2005
    Yes thank you very much, that makes sense.

    One followup question, in your table structure, you have a delete int column. How are you using that?

    And also, as I move from form to form how do I go about updating information in each table? The one reason I thought I'd use the sessionID was because I figured it might be good to use that aas a check to see if they have already entered data or needed to update it. I.e. If they were to hit back button and re-enter.

    So I guess what I'm asking is, am I establishing the info in the person table on the intial insert of data and how am I linking that person as they go from form to form? Sorry if these are stupid questions, just want to make sure I'm following your logic here.
    Last edited by dirt29; 09-05-2006 at 09:18 AM.

  5. #5
    Join Date
    Dec 2003
    England, UK
    i use the deleted columns to logically delete data from the database. so all the queries run against the db have to say "where deleted = 0" somewhere in them. the advantage of this is that you can restore the data very easily if it gets deleted accidentally. this obviously doesn't replace db backups or triggers creating complete audit trails, but it is useful for quick reference and restoring.

    anyway, enough of that.

    your database structure should essentially be unrelated to the application(s) that access it. it should just be able to store the data you need persisted in a normalised structure. obviously there are exceptions to this where it makes sense to do things based on the way the data is being handled outside the system.

    you don't really need to use the sessionid for checking what's been entered if you substitute it with something else (a person id). when a user submits the first data about a new person, you simply need to create the person record and get its id back, put that person id in session for later, then when you go to save each bit of person related data you just use the person id in session. this would let you enter more than one person per user session as well.

    to control the effects of users pressing back buttons and refresh buttons you need to use something like a pagestamp. if you were to put a value in session on each request and place it into the html page (in forms and anchors), you can then check if they match on the next request, meaning that the user has gone from the page before to the next page without doing anything else.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.32517 seconds
  • Memory Usage 2,878KB
  • Queries Executed 13 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (6)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (5)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates