Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting information out of forms in a SQLdatabase 3

Status
Not open for further replies.

emokid

Technical User
Oct 25, 2000
5
0
0
BE
I am new to ColdFusion, so this question might seem simple to you...
I am making my form dynamicly : I query the database, so the name of the input-field is #RegDescr# to have different names for each input-field.
The problem now is if I want to insert that information in another table, I tried to say in my INSERT-query : Values ('#Form.#RegDescr##'). But that doesn't seem to work. I've tried several other ways but I can't work it out.

Can somebody give me some tips how to fix this one ???

tx,
 
'#Form.#RegDescr##' should be '#Form.RegDescr#'
Try this and see if you have any other problems
 
Tx for the suggestion, but it doesn't seem to work :
it will look for a field in the form with the name RegDescr, and that one doesn't exist. It should be '#Form.x#', where x is the name of the field as it got out of the query.

any other suggestions ???

tx,

emokid
 
I'm not sure what your doing, maybe if you post a snip of your code i could help more, are you setting the field name like this:
<INPUT NAME=&quot;#RegDescr#&quot; TYPE&quot;inputtype&quot;>
if so make sure you have surrounded the statement with a <CFOUTPUT> tag which specifies the query name.

Any luck?
 
OK, here's the code I am working on.

---- this is the code on the first page ------
<cfquery name=&quot;strSQL&quot;
datasource=&quot;dbTravago&quot;
dbtype=&quot;ODBC&quot;
username=&quot;admin&quot;
password=&quot;&quot;>
SELECT * FROM tblRegions
</cfquery>

</head>

<body>
<CFFORM NAME=&quot;test&quot; action=&quot;test.cfm&quot;>
<cfoutput query=&quot;strSQL&quot;>
<PRE>
<cfinput type=&quot;text&quot; name=&quot;#RegDescr#&quot; value=&quot;#RegDescr#&quot;></cfinput>
</pre>
</cfoutput>
<input type=&quot;Submit&quot; Value=&quot;continue&quot;></input>
</cfform>

------ this is the code on the second page ------

<cfquery
name=&quot;SQLupd&quot;
datasource=&quot;dbTravago&quot;
dbtype=&quot;ODBC&quot;
username=&quot;admin&quot;
password=&quot;&quot;
debug=&quot;yes&quot;>
INSERT INTO tblRegionsupd ( RegDescr) VALUES ('#form.#RegDescr##')
</cfquery>


In the first page I give an overview of the existing regions, all in a seperate input-field. They need to be transferred into another table and some changes need to be made on them. The difficulty is that I can't give the name of the input-field to the next page, which I need to insert it in the table. I know how to work this out in asp, but coldfusion is still very new to me...

any suggestions ?

 
Changer the first page form section to look like this:

<CFSET InputList=&quot;&quot;>
<CFSET InputCount=0>

<CFFORM NAME=&quot;test&quot; action=&quot;test.cfm&quot;>
<cfoutput query=&quot;strSQL&quot;>
<PRE>
<cfinput type=&quot;text&quot; name=&quot;#RegDescr#&quot; value=&quot;#RegDescr#&quot;></cfinput>
</pre>
<CFSET InputCount = InputCount + 1>
<CFSET InputList=Insert(&quot;#RegDescr#&quot;, InputList, Len(InputList))>
<CFIF InputCount LESS THAN strSQL.RecordCount>
<CFSET InputList=Insert(&quot;,&quot;, InputList, Len(InputList))>
</CFIF>
</cfoutput>
<cfoutput>
<input type=&quot;hidden&quot; NAME=&quot;InputCount&quot; value=&quot;#strSQL.RecordCount#&quot;>
<input type=&quot;hidden&quot; NAME=&quot;InputList&quot; value=&quot;#InputList#&quot;>
</cfoutput>
<input type=&quot;Submit&quot; Value=&quot;continue&quot;>
</cfform>

This creates a string that contains a comma delinminated list of all the field names then stores it in the hidden input called &quot;InputList&quot;. Also the record count of the query is stored in the hiddeen input called &quot;InputCount&quot;. The list can then be parsed in the next page thus:

<CFSET ListCount=0>
<CFSET InputList=&quot;#Form.InputList#&quot;>

<CFLOOP CONDITION=&quot;ListCount LESS THAN #Form.InputCount#&quot;>
<CFSET ListCount=ListCount + 1>
<CFSET FieldName=SpanExcluding(InputList, &quot;,&quot;)>
<CFSET FieldContent=Evaluate(&quot;Form.#FieldName#&quot;)>
<CFOUTPUT>
<cfquery name=&quot;SQLupd&quot;
datasource=&quot;dbTravago&quot;
dbtype=&quot;ODBC&quot;
username=&quot;admin&quot;
password=&quot;&quot;
debug=&quot;yes&quot;>
INSERT INTO tblRegionsupd ( RegDescr) VALUES ('#FieldContent#')
</cfquery>
</CFOUTPUT>
<CFSET InputList = RemoveChars(InputList, 1, Find(&quot;,&quot;, &quot;#InputList#&quot;))>
</CFLOOP>

There may be more elegent solution out there but it's the first time i've tried that kinda thang and i'm still fairly new to cf myself.
I hope this gives the desired results and is what you are trying to achieve.

rgds
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top