Skip to main content
September 7, 2008
Answered

I can't get cfupdate tag to work. Please help.

  • September 7, 2008
  • 12 replies
  • 1456 views
Hello, I am trying to get an action file to work so that my form can be updated.

SQL update will work but cfupdate will not. WHY??? I can't figure it out and I feel like I have tried EVERYTHING. ANY SUGGESTIONS out there? My database is MICROsoft access.

more details --

this works:

<cfquery datasource="crcsignup">
UPDATE signuppractice
SET Field1='#FORM.Field1#'
WHERE ID=#FORM.ID#
</cfquery>

if i replace it with the cfupdate, it doesn't work:

<cfupdate datasource="crcsignup" tablename="signuppractice">

and the error message is:

The website cannot display the page
HTTP 500
Most likely causes:
The website is under maintenance.
The website has a programming error.

What you can try:
Refresh the page.

Go back to the previous page.

More information

This error (HTTP 500 Internal Server Error) means that the website you are visiting had a server problem which prevented the webpage from displaying.

For more information about HTTP errors, see Help.
This topic has been closed for replies.
Correct answer Dan_Bracuk
If you don't need that column for anything else, get rid of it. On your form page, don't give your buttons names.

12 replies

Inspiring
September 8, 2008
kena88 wrote:
> Here is the error I received:
> Duplicate output destination 'id'.

ID is already one of the form fields. So when you append "id = id" to the sql it probably invalidates the statement. I doubt you can include the same column twice like this:

UPDATE signuppractice
SET ID = ID,
....other columns ...,
ID = ID
WHERE ....

Bear in mind that using dynamic sql requires some thought. As you discovered, it has a number of pitfalls. One of which is that it can be more difficult to debug. The same applies to cfupdate.

Another thing about dynamic sql is that it requires data type information, which was not included in your original code. So unless all of your columns are "text" the omitting the type may cause syntax errors or wrong results. Personally, I would just code the regular update manually, rather than trying to make the update dynamic or using cfupdate. Cfupdate is rather limited.
September 8, 2008
good point, thanks!
Dan_BracukCorrect answer
Inspiring
September 8, 2008
If you don't need that column for anything else, get rid of it. On your form page, don't give your buttons names.
September 8, 2008
oh my. it seems I have solved the problem. thanks for all your help!!!

i ended up going with the <cfupdate> tag but had to add a column "SAVE" to my table. I didn't realize that the SAVE button is a formfield as well, so when I was trying to update the form, there was no corresponding column for the save button....
September 8, 2008
darn, same error message. could it have something to do with my computer or server settings??

code i tried:
<cfquery datasource="crcsignup">
UPDATE signuppractice
set
<cfloop list="#form.fieldnames#" index="thisfield">
thisfield=<cfqueryparam value="#(form[thisfield])#">,
</cfloop>
id = id
WHERE ID=#FORM.ID#
</cfquery>
September 8, 2008
FYI -- Here is the error I received: I'm not sure how to troubleshoot this one.

HTTP 500 internal server error.....

Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Duplicate output destination 'id'.
Inspiring
September 8, 2008
try this

update yourtable
set
<cfloop list = "#form.fieldnames# index = "thisfield">
#thisfield = <cfqueryparam value="#form[thisfield]#>,
</cfloop>
id = id
Inspiring
September 8, 2008
<cfloop collection=#form# item="myfield">
#variables[myfield]# = <cfqueryparam value = "#form[myfield]#">,
</cfloop>
id = id

The last line is to ensure something comes after the last comma.

However, if any field is not text, including the id field, you have to take another approach. Also, you don't need cfoutput tags inside cfquery tags.
September 8, 2008
TRied it, and got:

The website cannot display the page
HTTP 500
Most likely causes:
The website is under maintenance.
The website has a programming error.

What you can try:
Refresh the page.
Go back to the previous page.
More information

Here is the code exactly, I also tried it with "": cfloop collection="#form#"

<cfquery datasource="crcsignup">
UPDATE signuppractice
SET
<cfloop collection=#form# item="myfield">
#variables[myfield]# = <cfqueryparam value = "#form[myfield]#">,
</cfloop>
id = id
WHERE ID=#FORM.ID#
</cfquery>

Inspiring
September 8, 2008
kena88 wrote:
> TRied it, and got:
> The website cannot display the page
> HTTP 500

That is a generic message. For Internet Explorer, try disabling this option so the browser displays a more useful message.
http://www.communitymx.com/content/article.cfm?cid=A66B8

BKBK
Community Expert
Community Expert
September 8, 2008
Kena88,
I'm sure you will get more fruitful answers if you show your code here, explaining what you want to achieve.

September 8, 2008
Sorry -- here's what I'm going for. I need the update page to look for the fields that exist (cfloop list for fieldnames?) in the form and then update the corresponding table column with the value in that field. The fields are names Field1, Field2, Field3, etc. and correspond to the table column with the same name. I've pasted the code I'm working on into this mesage as well, in case it didn't attach.

Thanks

<cfquery datasource="crcsignup">
UPDATE signuppractice
SET
<cfloop collection=#form# item="myfield"> <cfoutput>
#myfield# = '#evaluate(myfield)#' </cfoutput>
</cfloop>
WHERE ID=#FORM.ID#
</cfquery>

Inspiring
September 7, 2008
My suggestion is to use cfquery instead of cfupdate. It will give you more flexibility.

If the number of form fields being received varies, write code to handle that.
September 7, 2008
Hi BKBK, Thanks for your reply.

The primary key is already ID. Also, the table has 60 columns (Field1, Field2, Field3, etc.) although to troubleshoot I have only been working with a single field, as I have been unable to get the cfupdate tag to work.

The "problem" is that the form fields are dynamic and I don't always have the same number of Fields being submitted to the action page. Therefore I can't just list them in the SQL or cfupdate attributes.

If I list them, I still get an error because some of the fields don't exist...
Hope this makes sense.