CFUPDATE

The CFUPDATE tag updates existing records in data sources.

Syntax

<CFUPDATE DATASOURCE="ds_name"
    DBTYPE="type"
    TABLENAME="table_name"
    USERNAME="username"
    PASSWORD="password"
    FORMFIELDS="field_names">

DATASOURCE

Required. Name of the data source that contains your table.

DBTYPE

Optional. The database driver type:

TABLENAME

Required. Name of the table you want to update.

USERNAME

Optional. If specified, USERNAME overrides the username value specified in the ODBC setup.

PASSWORD

Optional. If specified, PASSWORD overrides the password value specified in the ODBC setup.

FORMFIELDS

Optional. A comma-separated list of form fields to update. If this attribute is not specified, all fields in the form are included in the operation.

Example

<!--- This example shows the use of CFUPDATE to change
records in a datasource. --->

<!--- if Employee_ID has been passed to this form, then
perform the update on that record in the datasource --->

<CFIF IsDefined("form.Employee_ID")>
<!--- check that course_id is numeric --->
    <CFIF Not IsNumeric(form.Employee_ID)>
        <CFABORT>
    </CFIF>
<!--- Now, do the update --->
    <CFUPDATE DATASOURCE="HRApp"
  TABLENAME="Employees" 
FORMFIELDS="Employee_ID,FirstName,LastName,Department_ID, StartDate, 
Salary">
</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="GetEmployeeInfo" DATASOURCE="HRApp">
SELECT     Employee_ID, FirstName, LastName, Department_ID, StartDate, 
Salary
FROM       Employees
<CFIF IsDefined("url.Employee_ID")>
WHERE        Employee_ID = #Trim(url.Employee_ID)#
</CFIF>
ORDER by Employee_ID
</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.Employee_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>

  <INPUT TYPE="Hidden" NAME="Employee_ID" 
VALUE="<CFOUTPUT>#Trim(GetEmployeeInfo.Employee_ID)#</CFOUTPUT>">
  <P>Employee Name <BR> <INPUT TYPE="Text" NAME="FirstName" 
VALUE="<CFOUTPUT>#Trim(GetEmployeeInfo.FirstName)#</CFOUTPUT>">
                          <INPUT TYPE="Text" NAME="LastName" 
VALUE="<CFOUTPUT>#Trim(GetEmployeeInfo.LastName)#</CFOUTPUT>">
  <P>Department ID<BR>
  <INPUT TYPE="Text" NAME="Department_ID" 
VALUE="<CFOUTPUT>#Trim(GetEmployeeInfo.Department_ID)#</CFOUTPUT>"></P>
  <BR>
  <P>Start Date<BR>
  <INPUT TYPE="Text" NAME="StartDate" 
VALUE="<CFOUTPUT>#DateFormat(GetEmployeeInfo.StartDate)#</CFOUTPUT>">
</P>
  <P>Salary<BR>
  <INPUT TYPE="Text" NAME="Salary" 
VALUE="<CFOUTPUT>#DollarFormat(GetEmployeeInfo.Salary)#</CFOUTPUT>"></P>
  <P><INPUT TYPE="Submit" VALUE="Click to Update"></P>
  </FORM>
<CFELSE>
  <!--- Show the entire record set in CFTABLE form --->
  <table cellspacing="2" cellpadding="2" border="0">
    <tr>
        <th>Edit</th>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Department ID</th>
        <th>Start Date</th>
        <th>Salary</th>
    </tr>
    <CFOUTPUT query="GetEmployeeInfo">
    <tr>
        <td><a href='cfupdate.cfm?Employee_ID=#Employee_ID#'>Edit</a></
td>
        <td>#FirstName#</td>
        <td>#LastName#</td>
        <td>#Department_ID#</td>
        <td>#DateFormat(StartDate)#</td>
        <td>#DollarFormat(Salary)#</td>
    </tr>
    </CFOUTPUT>
</table>
</CFIF>

</BODY>
</HTML>