Updates records in a data source from data in a ColdFusion form or form Scope.
<cfupdate dataSource = "ds_name" tableName = "table_name" tableOwner = "name" tableQualifier = "qualifier" username = "username" password = "password" formFields = "field_names">
cfinsert,
cfprocparam,
cfprocresult,
cfquery,
cfqueryparam,
cfstoredproc,
cftransaction
New in ColdFusion MX: The connectString
, dbName
, dbServer
, dbtype, provider
and providerDSN
attributes are deprecated. Do not use them. They do not work, and might cause an error, in releases later than ColdFusion 5.
<!--- This example shows the use of CFUPDATE to change records in a datasource. ---> <!--- if course_ID has been passed to this form, then perform the update on that record in the datasource ---> <cfif IsDefined("form.Course_ID")> <!--- check that course_id is numeric ---> <cfif Not IsNumeric(form.Course_ID)> <cfabort> </cfif> <!--- Now, do the update ---> <cfupdate datasource="cfsnippets" tablename="Courses" formfields="Course_ID,Number,Descript"> </cfif> <!--- Perform a query to reflect any updated information if Course_ID is passed through a url, we are selecting a record to update ... select only that record with the WHERE clause. ---> <cfquery name="GetCourseInfo" DATASOURCE="cfsnippets"> SELECT Course_Number, Course_ID, Descript FROM Courses <cfif IsDefined("url.Course_ID")> WHERE Course_ID = #Trim(url.Course_ID)# </cfif> ORDER by Course_Number </cfquery> <html> <head> <title>CFUPDATE Example</title> <cfset css_path = "../../css"> <cfinclude template="../../resource/include/mm_browsersniff.cfm"> </head> <body> <H3>CFUPDATE Example</H3> <!--- If we are updating a record, don't show the entire list. ---> <cfif IsDefined("url.Course_ID")> <form method="post" action="index.cfm"> <H3>You can alter the contents of this record, and then click "Update" to use CFUPDATE and alter the database</H3> <P>Course Number <INPUT TYPE="Text" name="Number" value="<cfoutput>#Trim(GetCourseInfo.Course_Number)#</cfoutput>"> <P>Course Description<BR> <textarea name="Descript" cols="40" rows="5"> <cfoutput>#Trim(GetCourseInfo.Descript)#</cfoutput> </textarea><br> <input type="Hidden" NAME="Course_ID" value="<cfoutput>#Trim(GetCourseInfo.Course_ID)#</cfoutput>"> <p><input type="Submit" value="Click to Update"> </form> <cfelse> <!--- Show the entire record set in CFTABLE form ---> <cftable query="GetCourseInfo" htmltable colheaders> <cfcol text="<a href='index.cfm?Course_ID=#Trim(Course_ID)#'>Edit Me</a>" width=10 header="Edit<br>this Entry"> <cfcol text="#Trim(Course_Number)#" WIDTH="4" HEADER="Course Number"> <cfcol text="#Trim(Descript)#" WIDTH=100 HEADER="Course Description"> </cftable> </cfif> </body> </html>