Multiple values into a single field

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Multiple values into a single field

    Hi, I've created a form that is all radio buttons, each question looks like:

    <legend>Choose the option which best describes your hair type:</legend>
    <cfinput type="radio" name="hairtype" value="8"> Dry hair<br>
    <cfinput type="radio" name="hairtype" value="9">Oily Hair<br>
    <cfinput type="radio" name="hairtype" value="10">Normal hair<br>
    <cfinput type="radio" name="hairtype" value="11">Sensitive Scalp<br>
    </fieldset>

    Once submitted the form gives me a list of values (answers) which looks like
    this: (1,2,3,4).
    I want to insert these values, in a comma delimited list, into one field in my
    database, but coldfusion wants the same amount of fields as there are values...

    My processing code:
    <cfquery name="InsertPref" datasource="030902ics3kla">
    INSERT into People (Pref)
    VALUES (#Form.skintype#, #form.hairtype#, #form.haircolour#)
    WHERE ID= #Cookie.BodyShop#
    </cfquery>

    Any ideas?
    Katie



    ktmx Guest

  2. Similar Questions and Discussions

    1. linking error & how to return 2 values from a single method in a COM dll program?
      hi ppl i have created an ATL COM appwizard project as a dll server type named TestCOMasp6. i have created a ASP component object named...
    2. DataGrid - Multiple values in single Row
      you can set a global variable say "categ" then loop through the items in itemdatabound event of datagrid and set the value of categ to the new...
    3. form: single line -- multiple text boxes -- one typing field - how?
      please excuse my ignorance. am a newbie. I saw a fillable form, that shows:- a single line with multiple text boxes for entering each letter of a...
    4. Is there a way to assign multiple variables a single value on a single line?
      i tried $f1, $f2, $f3 = '1'; and list($f1, $f2, $f3) = 1; neither work... second obviously cuz its looking for an array on the right side,...
    5. Single field to multiple records in one transaction??
      Im hooking into an Access 2k database via FrontPage 2k... I want to submit a single text box into 5 new records at once. Any help would be much...
  3. #2

    Default Re: Multiple values into a single field

    Hi KAtie,

    The list is fine. Coldfusion is just expecting three fields from that form,
    skintype, hairtype, and haircolour. If they are not filled in in the form they
    will not be present. If you use "cfparam" to set default values on your submit
    page than if they are not selected they will be inserted with the default
    values! You could also set up those other fields as hidden fields in your form
    and submit a value that way. Many ways to skin a cat!

    Mike

    mat1492 Guest

  4. #3

    Default Re: Multiple values into a single field

    First of all, it looks like your INSERT statement is incorrect, since you have
    an unnecessary WHERE clause. Also, I will make the observation that you have a
    less than desirable data model since your design requires multiple values of
    hairtype in a single database field. This is a normalization issue, and should
    probably be resolved by migrating your hairtype to a separate table linked by
    an associative entity. As for implementing it as designed, I'll let someone
    else explain how you can insert this LOV into this field - probably need to
    include single quotes around each item, then use preservesinglequotes in your
    insert statement.

    Phil

    paross1 Guest

  5. #4

    Default Re: Multiple values into a single field

    Katie,

    Sorry shold have looked at all your code before answering. the correct format
    for inserting would be:

    <cfquery name="InsertPref" datasource="030902ics3kla">
    INSERT into People (skintype, hairtype, haircolour)
    VALUES ('#Form.skintype#', '#form.hairtype#', '#form.haircolour#')
    WHERE ID= #Cookie.BodyShop#
    </cfquery>

    You need to tell it which fields in the databse to insert the form fields
    into. Given the table field names are the same!

    Mike

    mat1492 Guest

  6. #5

    Default Re: Multiple values into a single field

    Mike,

    Without the WHERE clause, of course, unless you replace the VALUES with a SELECT..FROM..WHERE.

    Phil
    paross1 Guest

  7. #6

    Default Re: Multiple values into a single field

    Phil,

    Your right! You only need to use the "where" clause if you were updating the record not inserting it. I really should read the whole post before replying:)

    Mike
    mat1492 Guest

  8. #7

    Default Re: Multiple values into a single field

    Also, technically, you don't need to explicitly include the field names if the
    VALUES clause contains values for all of the fields in the table in the correct
    order. The danger of doing this, however, is if your ever alter your table and
    add new fields, then you would have to alter every insert statement in every
    template to add the field value, even if it was not a mandatory field. The safe
    way is to do as Mike suggested and explicitly list the fields, but I just
    wanted you to know that it is only necessary if you are inserting rows where
    your insert statement does not contain a value for each field in the table.

    Phil

    paross1 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