home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / CHIPCD_02_2002.iso / Internet / Macromedia ColdFusion Server 5 / coldfusion-50-win-us.exe / data1.cab / Examples / CFDOCS / snippets / cfupdate.cfm < prev    next >
Encoding:
Text File  |  2001-06-13  |  2.3 KB  |  71 lines

  1. <!--- This example shows the use of CFUPDATE to change
  2. records in a datasource. --->
  3.  
  4. <!--- if course_ID has been passed to this form, then
  5. perform the update on that record in the datasource --->
  6.  
  7. <CFIF IsDefined("form.Course_ID")>
  8. <!--- check that course_id is numeric --->
  9. <CFIF Not IsNumeric(form.Course_ID)>
  10.     <CFABORT>
  11. </CFIF>
  12. <!--- Now, do the update --->
  13.   <CFUPDATE DATASOURCE="cfsnippets"
  14.   TABLENAME="Courses" FORMFIELDS="Course_ID,Course_Num,Descript">
  15. </CFIF>
  16.  
  17. <!--- Perform a query to reflect any updated information
  18. if Course_ID is passed through a url, we are selecting a
  19. record to update ... select only that record with the
  20. WHERE clause.
  21.  --->
  22. <CFQUERY NAME="GetCourseInfo" DATASOURCE="cfsnippets">
  23. SELECT     Course_Num, Course_ID, Descript
  24. FROM       Courses
  25. <CFIF IsDefined("url.Course_ID")>
  26. WHERE        Course_ID = #Trim(url.Course_ID)#
  27. </CFIF>
  28. ORDER by Course_Num
  29. </CFQUERY>
  30.  
  31. <HTML>
  32. <HEAD>
  33. <TITLE>CFUPDATE Example</TITLE>
  34. </HEAD>
  35.  
  36. <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  37. <BODY  bgcolor="#FFFFD5">
  38.  
  39. <H3>CFUPDATE Example</H3>
  40.  
  41. <!--- If we are updating a record, don't show
  42. the entire list. --->
  43. <CFIF IsDefined("url.Course_ID")>
  44.   <P><H3><a href="cfupdate.cfm">Show Entire List</A></H3>
  45.  
  46.   <FORM METHOD="POST" ACTION="cfupdate.cfm">
  47.   <H3>You can alter the contents of this
  48.   record, and then click "Update" to use
  49.   CFUPDATE and alter the database</H3>
  50.  
  51.   <P>Course Number <INPUT TYPE="Text" NAME="Number" VALUE="<CFOUTPUT>#Trim(GetCourseInfo.Course_Num)#</CFOUTPUT>">
  52.   <P>Course Description<BR>
  53.   <TEXTAREA NAME="Descript" COLS="40" ROWS="5">
  54.   <CFOUTPUT>#Trim(GetCourseInfo.Descript)#</CFOUTPUT>
  55.   </TEXTAREA>
  56.   <BR>
  57.   <INPUT TYPE="Hidden" NAME="Course_ID" VALUE="<CFOUTPUT>#Trim(GetCourseInfo.Course_ID)#</CFOUTPUT>">
  58.   <P><INPUT TYPE="Submit" VALUE="Click to Update">
  59.   </FORM>
  60. <CFELSE>
  61.   <!--- Show the entire record set in CFTABLE form --->
  62.   <CFTABLE QUERY="GetCourseInfo" HTMLTABLE COLHEADERS>
  63.     <CFCOL  TEXT="<a href='cfupdate.cfm?Course_ID=#Trim(Course_ID)#'>Edit Me</a>" WIDTH=10 HEADER="Edit<br>this Entry">
  64.     <CFCOL  TEXT="#Trim(Course_Num)#" WIDTH="4" HEADER="Course Number">
  65.     <CFCOL  TEXT="#Trim(Descript)#" WIDTH=100 HEADER="Course Description">
  66.   </CFTABLE>
  67. </CFIF>
  68.  
  69. </BODY>
  70. </HTML>       
  71.