<cfinsert> and <cfupdate> are tags that simplify the process of database inserts and updates, respectively. They effectively build a dynamic SQL statement based on the FORM variable structure and submit it like a standard <cfquery> with the appropriate SQL statement. Consequently, they are easier to use than <cfquery> and SQL code, but they are also less flexible and have some limitations. Only datasource and tablename are required attributes. <cfinsert> and <cfupdate> are used like this: <!--- inserting a record ---> <cfinsert datasource="dsn" tablename="users" formfields="LastName, FirstName"> <!--- updating a record ---> <cfupdate datasource="dsn" tablename="users" formfields="LastName, FirstName"> <cfinsert> and <cfupdate> have the following restrictions:
The formfields attribute acts as a mask, allowing only specified form fields to be included in the operation. If formfields is not present, all the form fields are submitted. Other tag attributes are available to override default settings in the data source connection. TIP <cfparam> can be used to create default form fields for use with <cfinsert> and <cfupdate>. |