<!--- 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     Number, Course_ID, Descript
FROM       Courses
<CFIF IsDefined("url.Course_ID")>
WHERE 	   Course_ID = #Trim(url.Course_ID)#
</CFIF>
ORDER by Number
</CFQUERY>

<HTML>
<HEAD>
<TITLE>CFUPDATE Example</TITLE>
</HEAD>

<BASEFONT FACE="Arial, Helvetica" SIZE=2>
<BODY  bgcolor="#FFFFD5">

<H3>CFUPDATE Example</H3>

<!--- If we are updating a record, don't show
the entire list. --->
<CFIF IsDefined("url.Course_ID")>
  <P><H3><a href="cfupdate.cfm">Show Entire List</A></H3>

  <FORM METHOD="POST" ACTION="cfupdate.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.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='cfupdate.cfm?Course_ID=#Trim(Course_ID)#'>Edit Me</a>" WIDTH=10 HEADER="Edit<br>this Entry">
    <CFCOL  TEXT="#Trim(Number)#" WIDTH="4" HEADER="Course Number">
    <CFCOL  TEXT="#Trim(Descript)#" WIDTH=100 HEADER="Course Description">
  </CFTABLE>
</CFIF>

</BODY>
</HTML>       
