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!

cfinsert problem submitting data to a table

Status
Not open for further replies.

becarnes

Programmer
Jul 9, 2002
8
0
0
US
I am having problem with a cfinsert. I am using a dropdown on one form to dynamically choose a table and then using a cfif to determine which table it will go to. I am using cfset inside the form to make sure the info passes again and when I get to inserting the data I get an error interpreting the cfinsert. I need help. Here is the code

<cfif #item_opt# IS &quot;RING&quot;>

<form action=&quot;insert_ring.cfm&quot; methode=&quot;post&quot;><p>
<cfset item_opt=&quot;RING&quot;>
Itemnumber
<input type=&quot;text&quot; name=&quot;ITEMNUMBER&quot; size=&quot;15&quot; maxlength=&quot;15&quot;>
<P>
Metal
<input type=&quot;text&quot; name=&quot;METAL&quot; size=&quot;50&quot; maxlength=&quot;50&quot;>
<P>
Price per size
<input type=&quot;text&quot; name =&quot;PRICE_PER_SIZE&quot;size=&quot;15&quot; maxlength=&quot;15&quot;>
<P>
Stone
<input type=&quot;text&quot;name=&quot;STONE&quot; size=&quot;50&quot; maxlength=&quot;50&quot;>
<P>
Smallest size
<input type=&quot;text&quot;name=&quot;MIN_SIZE&quot; size=&quot;15&quot; maxlength=&quot;15>
<P>
Largest size
<input type=&quot;text&quot; name=&quot;MAX_SIZE&quot; size=&quot;15&quot; maxlength=&quot;15&quot;>


<input type=&quot;submit&quot; Value=&quot;Add item&quot;>

Here is the code for inputting the data
<cfinsert datasource=&quot;ITEMS&quot; tablename=&quot;form.item_opt&quot;>


<cfoutput>Item added to '#form.item_opt#'</cfoutput>
I get this error
ODBC Error Code = S1C00 (Driver not capable)


[Microsoft][ODBC Microsoft Access Driver]Optional feature not implemented



The error occurred while processing an element with a general identifier of (CFINSERT), occupying document position (10:1) to (10:55).

 
Try adding ## to the TableName property value:

=== START CODE EXAMPLE ===
<cfinsert datasource=&quot;ITEMS&quot; tablename=&quot;#form.item_opt#&quot;>
=== END CODE EXAMPLE === - tleish
 
Thanks I think I have tried it both ways but I am not sure.
 
I tried what you said and now I get this message

An error occurred while evaluating the expression:


&quot;#form.item_opt#&quot;



Error near line 10, column 42.
--------------------------------------------------------------------------------

Error resolving parameter FORM.ITEM_OPT


The specified form field cannot be found. This problem is very likely due to the fact that you have misspelled the form field name.



The error occurred while processing an element with a general identifier of (CFINSERT), occupying document position (10:1) to (10:57
 
FORM.item_opt does not exist on your insert page because you are not passing it as a form item. You can do this by making it a hidden field somewhere between your form tags:

<input type=&quot;hidden&quot; name=&quot;item_opt&quot; value=&quot;RING&quot;>

I must caution you on passing database table names through FORM and URL variables, however. You generally don't want to pass any data that can compromise your server, unless you validate it all before your program passes it along to your database code. Passing database commands, queries, table names, etc. in a way users can change them by rolling their own forms is a very bad idea. Always check to make sure you data is valid before passing it to your database.

-Tek
 
Ok. I have a cfif that determines which table it inserts into. I was thinking the same thing this morning. Are you suggesting I try to just use the tablename because my form input will only go to one page depending on the cfif that is true.
 
Yes, you can put the hidden field in your form without a dynamic variable because you have a cfif checking to see if item_opt is &quot;RING&quot;. So if you already know it is, you can use the hidden field line I gave you because you know the table will be &quot;RING&quot;.

-Tek
 
Thanks for all your help. I got it working and since I hardcoded my table names based on my first form dropdown the hidden field pass worked great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top