problem saving form results to a database table

Ask a Question related to Coldfusion - Getting Started, Design and Development.

  1. #1

    Default problem saving form results to a database table

    Coldfusion MX
    MSDE 2000

    I have a form on a page which users either fill in text or check radio
    buttons. The form has the following properties:

    <FORM action="sampleUpdate.cfm" METHOD="post" enctype="multipart/form-data"
    NAME="MainForm" >


    The sampleUpdate.cfm form writes the values in the form back to the SQL
    table:

    <cfquery datasource="SurveySQL">
    INSERT INTO dbo.Results(dbo.Results.RID,
    dbo.Results.QID,dbo.Results.ResponderName,dbo.Resu lts.Company,dbo.Results.[P
    osition],dbo.Results.Email,dbo.Results.Q1,dbo.Results.Q2,d bo.Results.Q3,dbo.
    Results.Q4,dbo.Results.Q5,dbo.Results.Q6,dbo.Resul ts.Q7,dbo.Results.Q8,
    dbo.Results.Q9, dbo.Results.Q10, dbo.Results.Q11, dbo.Results.Q12,
    dbo.Results.Q13 )
    VALUES
    ('999','1','#form.wsb33#','#form.wsb34#','#form.ws b35#','#form.wsb36#','#for
    m.wsb0#',
    '#form.wsb1#','#form.wsb2#','#form.wsb3#','#form.w sb4#','#form.wsb5#','#form
    ..wsb6#','#form.wsb7#',
    '#form.wsb8#','#form.wsb9#','#form.wsb10#','#form. wsb11#','#form.wsb12#')
    </cfquery>

    This all works fine and the Result table is updated provided that the user
    has completed each item on the form.

    If the user misses out a question such as No. 3 I get an 'Undefined wsb3'
    error when trying to run the Insert query.

    I want the user to have the flexability to miss out questions if they so
    desire and wonder if there is a way to intercept the answer from the
    #form.wsb3# variable and check if it is defined or null. I tried using
    ISDEFINED() and IFNULL() within the query but to no avail.

    Any help would be much appreciated.

    Regards

    June




    June Macleod Guest

  2. Similar Questions and Discussions

    1. Display results from a database in a table side by side
      While working on a page, I needed to display titles for certain series organized in a table. But I need these organized side by side. In other...
    2. Query results don't display properly in results table.IGNORE PREVIOUS
      :disgust; I need to display the results of a query. The query runs properly. My problem is having specific results display in specific locations in...
    3. Query results don't display properly in results table.
      :disgust; I need to display the results of a query. The query runs properly. My problem is having specific results display in specific locations in...
    4. Problem with accessing table in access database
      i had a working site with iis5 winxp professional on a p4 machine. suddenly i am having problems with and the asp pages which have some updating...
    5. Saving serialized data to database problem
      Hi! Anyone who knows about saving serialized data to database, coz I have a problem with that. If I just serialize my session data and then...
  3. #2

    Default Re: problem saving form results to a database table

    if you're using checkboxes then they don't get passed across if they haven't
    been checked.

    Your best solution would be to use cfparam to param values to a default if
    they haven't been selected, eg, FALSE, NO etc

    <cfparam name="form.myformfield" default="False">

    make sense?

    johnab Guest

  4. #3

    Default Re: problem saving form results to a database table

    Unchecked radio buttons will not pass the button's name to the action page,
    thereby making it undefined. For each form variable, place a CFPARAM at the
    top of the action page:

    <CFPARAM NAME="wsb1" DEFAULT="">

    This defines wsb1 as "" if it is not provided by the form page; if it is
    present, it has the value entered on the form.

    jdeline Guest

  5. #4

    Default Re: problem saving form results to a database table

    1) The cfparam tags are to be placed just before the query.

    2) As Johnab and Jdeline suggest, you have to do something to ensure that radio
    and checkbox field-names will be submitted. For example, use the
    checked-attribute.

    <input type="Radio" name="wsb3" value="answer3a" checked>
    <input type="Radio" name="wsb3" value="answer3b">

    3) There is an alternative solution to your problem, which may be useful when
    the
    number of form fields is large. For example, it may save you form writing
    many
    cfparam tags for the same default value. If your form is

    <FORM action="sampleUpdate.cfm" METHOD="post" enctype="multipart/form-data"
    NAME="MainForm" >
    wsb1 <input name="wsb1" type="Text" size="20" maxlength="20"><br>
    wsb2: <input type="Radio" name="wsb2" value="answer_1" checked><br>
    <input type="Radio" name="wsb2" value="answer_2"><br><br>
    etc.
    etc.
    <input name="score" type="Submit" value="log in">
    </form>

    then you can do something like this on your action-page, sampleUpdate.cfm,
    just before the query:



    <cfif isdefined("Form.fieldNames")>
    <cfloop list="#Form.fieldNames#" index="formfield">
    <!--- Considering all fields except the submit-field, if field
    value is empty, enter an "x". --->
    <cfif NOT(formfield is "score")>
    <cfset formfieldValue = Evaluate("form.#formfield#")>
    <cfif Len(formfieldValue) EQ 0>
    <cfset form[formfield] = "x">
    </cfif>
    </cfif>
    </cfloop>
    </cfif>

    BKBK Guest

  6. #5

    Default Re: problem saving form results to a database table

    Thank you all for your responses.

    I now understand what the problem is and was able to get it working.

    Much appreciated!

    June


    "June Macleod" <junework@hotmail.com> wrote in message
    news:dkfkdh$qh8$1@forums.macromedia.com...
    > Coldfusion MX
    > MSDE 2000
    >
    > I have a form on a page which users either fill in text or check radio
    > buttons. The form has the following properties:
    >
    > <FORM action="sampleUpdate.cfm" METHOD="post"
    enctype="multipart/form-data"
    > NAME="MainForm" >
    >
    >
    > The sampleUpdate.cfm form writes the values in the form back to the SQL
    > table:
    >
    > <cfquery datasource="SurveySQL">
    > INSERT INTO dbo.Results(dbo.Results.RID,
    >
    dbo.Results.QID,dbo.Results.ResponderName,dbo.Resu lts.Company,dbo.Results.[P
    >
    osition],dbo.Results.Email,dbo.Results.Q1,dbo.Results.Q2,d bo.Results.Q3,dbo.
    > Results.Q4,dbo.Results.Q5,dbo.Results.Q6,dbo.Resul ts.Q7,dbo.Results.Q8,
    > dbo.Results.Q9, dbo.Results.Q10, dbo.Results.Q11, dbo.Results.Q12,
    > dbo.Results.Q13 )
    > VALUES
    >
    ('999','1','#form.wsb33#','#form.wsb34#','#form.ws b35#','#form.wsb36#','#for
    > m.wsb0#',
    >
    '#form.wsb1#','#form.wsb2#','#form.wsb3#','#form.w sb4#','#form.wsb5#','#form
    > .wsb6#','#form.wsb7#',
    > '#form.wsb8#','#form.wsb9#','#form.wsb10#','#form. wsb11#','#form.wsb12#')
    > </cfquery>
    >
    > This all works fine and the Result table is updated provided that the user
    > has completed each item on the form.
    >
    > If the user misses out a question such as No. 3 I get an 'Undefined wsb3'
    > error when trying to run the Insert query.
    >
    > I want the user to have the flexability to miss out questions if they so
    > desire and wonder if there is a way to intercept the answer from the
    > #form.wsb3# variable and check if it is defined or null. I tried using
    > ISDEFINED() and IFNULL() within the query but to no avail.
    >
    > Any help would be much appreciated.
    >
    > Regards
    >
    > June
    >
    >
    >
    >

    June Macleod Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139