Skip to main content
Participating Frequently
February 5, 2007
Question

update link shows the first record only

  • February 5, 2007
  • 2 replies
  • 592 views
I have done the update record many times. It has always worked in the past. Not today!

I have an update link on my main page. When I click the link it only shows the first record, no matter which record I choose on the main page to update. I am sending the URL parameter. The add record and delete record behaviors work for any record. Just not the update.

I have tried to build the table and make it work as well as using the update record wizard with no luck. It seems stuck on the default=1 parameter in the page and I only get the default.

Here's the code the wizard generates:
<cfif MM_Username EQ "">
<cfset MM_referer=CGI.SCRIPT_NAME>
<cfif CGI.QUERY_STRING NEQ "">
<cfset MM_referer=MM_referer & "?" & CGI.QUERY_STRING>
</cfif>
<cfset MM_failureURL="login.cfm?accessdenied=" & URLEncodedFormat(MM_referer)>
<cflocation url="#MM_failureURL#" addtoken="no">
</cfif>
<cfset CurrentPage=GetFileFromPath(GetTemplatePath())>
<cfif IsDefined("FORM.MM_InsertRecord") AND FORM.MM_InsertRecord EQ "form1">
<cfquery datasource="dsncris">
INSERT INTO photos (name, link, "description", "year", category)
VALUES (<cfif IsDefined("FORM.name") AND #FORM.name# NEQ "">
<cfqueryparam value="#FORM.name#" cfsqltype="cf_sql_clob" maxlength="100">
<cfelse>
''
</cfif>
,
<cfif IsDefined("FORM.link") AND #FORM.link# NEQ "">
<cfqueryparam value="#FORM.link#" cfsqltype="cf_sql_clob" maxlength="150">
<cfelse>
''
</cfif>
,
<cfif IsDefined("FORM.description") AND #FORM.description# NEQ "">
<cfqueryparam value="#FORM.description#" cfsqltype="cf_sql_clob" maxlength="1073741823">
<cfelse>
''
</cfif>
,
<cfif IsDefined("FORM.year") AND #FORM.year# NEQ "">
<cfqueryparam value="#FORM.year#" cfsqltype="cf_sql_clob" maxlength="4">
<cfelse>
''
</cfif>
,
<cfif IsDefined("FORM.category") AND #FORM.category# NEQ "">
<cfqueryparam value="#FORM.category#" cfsqltype="cf_sql_clob" maxlength="1">
<cfelse>
''
</cfif>
)</cfquery>
<cflocation url="main.cfm?updateok=true">
</cfif>
<cfparam name="URL.ID" default="1">
<cfquery name="rsupd" datasource="dsncris">
SELECT *
FROM photos
WHERE ID =
<cfqueryparam value="#URL.ID#" cfsqltype="cf_sql_numeric">
</cfquery>


I have not seen this line: <cfparam name="URL.ID" default="1"> before in my other update pages that seem to work properly. I am using an Access ODBC database. Should I use the Access Unicode instead of Access for the ODBC connection?

Anyone else having this problem and how did you solve it?

Thanks in advance for any help.
This topic has been closed for replies.

2 replies

Inspiring
February 5, 2007
I don't see any update language in this code.

Your final cfquery, named "rsupd", only does a SELECT, no UPDATE.

It would need to look like:

UPDATE photos
SET photos.field1 = (ETC..., either a straight variable passed or cfqueryparamvalue).

- Mike
hs4uAuthor
Participating Frequently
February 5, 2007
Thanks for the replies. The info has no problems updating if I change it. The only problem is it only returns to the update form the first record, oo matter which record I click the update for.

Kills me that I have done this many times before without a hitch. Now all I get with the update is a hitch.

Any other suggestions? Why would the wizard not return the correct code to make it work?
hs4uAuthor
Participating Frequently
February 7, 2007
I am really stumped. I have run the wizard several times, changed the ID to pID in case it was having trouble with that, manually entered the update record but it only returns the record 1. I deleted the record one and now it says it cannot find the records at all. In the url it is passing record 5 or whichever record I tell it to. Somehow it is defaulting to record ID=1 which no longer exists.

I think it is only showing this line which does not exist in any other page I have made using the update wizard nor manually building the page: <cfparam name="URL.ID" default="1">, yet, if I delete it the page throws an error that can't find record ID=1.

What happened? I have build this several times in CFMX7 without a hitch, but now with the cfparam stuff it does not work.

Please, I need help! In the url it is passing record 5 or whichever record I tell it to. The update page is incorrectly reading the code.

Here is the new code from the web wizard:

<cfparam name="URL.pID" default="null">
<cfset CurrentPage=GetFileFromPath(GetTemplatePath())>
<cfif IsDefined("FORM.MM_UpdateRecord") AND FORM.MM_UpdateRecord EQ "form1">
<cfquery datasource="dsncris">
UPDATE photos
SET name=<cfif IsDefined("FORM.name") AND #FORM.name# NEQ "">
<cfqueryparam value="#FORM.name#" cfsqltype="cf_sql_clob" maxlength="100">
<cfelse>
''
</cfif>
, link=
<cfif IsDefined("FORM.link") AND #FORM.link# NEQ "">
<cfqueryparam value="#FORM.link#" cfsqltype="cf_sql_clob" maxlength="150">
<cfelse>
''
</cfif>
, "description"=
<cfif IsDefined("FORM.description") AND #FORM.description# NEQ "">
<cfqueryparam value="#FORM.description#" cfsqltype="cf_sql_clob" maxlength="1073741823">
<cfelse>
''
</cfif>
, "year"=
<cfif IsDefined("FORM.year") AND #FORM.year# NEQ "">
<cfqueryparam value="#FORM.year#" cfsqltype="cf_sql_clob" maxlength="4">
<cfelse>
''
</cfif>
, category=
<cfif IsDefined("FORM.category") AND #FORM.category# NEQ "">
<cfqueryparam value="#FORM.category#" cfsqltype="cf_sql_clob" maxlength="1">
<cfelse>
''
</cfif>
WHERE pID=<cfqueryparam value="#FORM.pID#" cfsqltype="cf_sql_numeric">
</cfquery>
<cflocation url="main.cfm?updateok=true">
</cfif>
<cfquery name="rsedit" datasource="dsncris">
SELECT category
FROM photos
WHERE pID =
<cfqueryparam value="#URL.pID#" cfsqltype="cf_sql_numeric">
</cfquery>

Anyone from Macromedia willing to help? Please???
Participant
February 5, 2007
try giving permission to the object. for example, if ur table name is employee, use the syntax, dbo.employee