This content has been marked as final. Show 5 replies
Individual text fields for every var is the way I would do it.
I don't think I was clear in my original explanation. I need all the variables in Column 1 to go into the same column in the database and of the variables in Column 2 to go into another column in the database. If I create a unique text field for each variable won't they each need their own column in the database? I need them to be inserted into one column, and the variables in Column 1 correspond to the variables in Column 2. I know I need to do a cfloop statement, but I need a little more guideance on how to set up the form.
If I create a unique text field for each variable won't they each need their own column in the database?
As long as you know the name of the form field and what you are supposed to do with it, write your code accordingly.
So the different columns are grouped with rows?
You can use row numbers in your field names to associate the columns with a particular record. For example, let's say you want 5 rows to enter last names and first names:
<CFSET maxrow = 5>
<CFLOOP INDEX="rownum" FROM="1" TO="#maxrow#"><CFOUTPUT>
Last name: <INPUT TYPE="text" NAME="lname#rownum#" SIZE="25">
First name: <INPUT TYPE="text" NAME="fname#rownum#" SIZE="15"><BR>
This will give you a series of fields such as lname1, fname1, lname2, fname2, etc.
In your form, you can also include a hidden field to indicate the number of rows.
When you process the form, you loop again to insert each row:
<CFLOOP INDEX="onerow" FROM="1" TO="#Form.numrows#">
<CFQUERY NAME="addRec" DATASOURCE="mydsn">
INSERT INTO mytable (lastname, firstname)
VALUES ('#Form["lname" & onerow]#)', '#Form["fname" & onerow]#')