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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing Autonumber Primary Key in UPDATE 1

Status
Not open for further replies.

andy570

Technical User
Jan 5, 2004
40
US
DB newbie here - I have MS Access table with the following fields PressID, PRTitle, Month, Day, and Year. Once the information is posted I want to be able to update/edit if necessary.

The following is the code I have used to list the current data: With the html removed

<cfquery name=&quot;pressreleaselist&quot; datasource=&quot;safedb&quot;>
SELECT * FROM PressRelease
ORDER BY Month ASC, Day DESC, Year DESC
</cfquery>

<cfoutput query=&quot;pressreleaselist&quot;>
<a href=&quot;updatepressreleaseform.cfm?Month=#Month#&Day=#Day#&Year=#Year#&quot;>#MonthAsString('#Month#')# #Day#, #Year# #PRTitle#
</cfoutput>

on updatepressrelease page I use the following code:

<cfquery name=&quot;pressreleaselist&quot; datasource=&quot;safedb&quot;>
SELECT * FROM PressRelease
WHERE Month=#URL.Month# AND Day=#URL.Day# AND Year=#URL.Year#
</cfquery>

Inside the CFFORM I have added the following to embed the primary key:
<cfoutput>
<input type=&quot;hidden&quot; name=&quot;PressID&quot; value=&quot;#pressreleaselist.Month&Day&Year#&quot;>
</cfoutput>

This is followed by inputs for the various fields.

On the final edit page I have used the following code:

<cfquery datasource=&quot;safedb&quot;>
UPDATE PressRelease
SET Month='#Trim(FORM.Month)#',
Day='#Trim(FORM.Day)#',
Year='#Trim(FORM.Year)#',
PRTitle='#Trim(FORM.PRTitle)#',
PressRelease='#Trim(FORM.PressRelease)#'
WHERE PressID=#FORM.PressID#
</cfquery>

When I view the results I see that instead of editing the existing record it has inserted a new.

Any suggestions as to what I am doing wrong?

Thanks again from a newbie!
 
Is your PressID an Autonumber datatype? If so, I'm not sure I understand how you're assigning the value for it in the form:

<input type=&quot;hidden&quot; name=&quot;PressID&quot; value=&quot;#pressreleaselist.Month&Day&Year#&quot;>

Shouldn't this be:

<input type=&quot;hidden&quot; name=&quot;PressID&quot; value=&quot;#pressreleaselist.PressID#&quot;>

where you pulled the PressID from the query?

Hope This Helps!

Ecobb

&quot;Alright Brain, you don't like me, and I don't like you. But lets just do this, and I can get back to killing you with beer.&quot; - Homer Simpson
 
Thanks for all the help! It worked great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top