Ask a Question related to Coldfusion Database Access, Design and Development.
-
ktmx #1
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
-
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... -
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... -
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... -
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,... -
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... -
mat1492 #2
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
-
paross1 #3
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
-
mat1492 #4
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
-
paross1 #5
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
-
mat1492 #6
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
-
paross1 #7
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



Reply With Quote

