Lesson
1 - Inserting Data
Displayed below is a standard HTML Form. If you enter data into the form and press the "Enter Course Information" button the data will be automatically appended to the CourseList table of the database:
If you view the source of the form you will see what looks like a standard HTML Form. In this example, the ACTION attribute of the form directs the browser to submit the form to Cold Fusion:
<FORM ACTION="/~wsapi/cfusion?Template=/cfstand/tutorial/step1b.dbm"
METHOD="POST">
When the user presses the 'Enter Course Information' button the form fields CourseName, Department_ID, CourseLevel, CourseNumber and CourseDescription will be sent to Cold Fusion for processing.
In the above example a Template parameter is included at the end of the URL, What does this parameter refer to?
Templates are files containing HTML and DBML (Database Markup Language) tags which are processed by Cold Fusion. This processing consists of resolving DBML tags into database queries, inserting data to or retrieving data from the database, then returning to the client a dynamically generated HTML page based on the database operations performed.
The template parameter in this case references a file called 'step1b.dbm' located in the '/cfstand/tutorial' directory. The source code for this template file is displayed below.
In this example, the DBML template performs two tasks:
If you examine the contents of the template file, you will find the following DBML tag at the very top of it:
<DBINSERT DATASOURCE="CF Examples" TABLENAME="CourseList">
This tag tells Cold Fusion to insert the data passed from the form into a database table. Cold Fusion determines the name and location of the database table to insert the data into using the DATASOURCE and TABLENAME attributes of the DBINSERT tag.
These attributes specify which database table to append the contents of the form into. But how does Cold Fusion know which specific fields in the table to insert data into?
The answer is that it uses the NAME attribute of the form fields to determine which database fields the data should be entered into. In the above example, the values entered in the CourseName, Department_ID, CourseLevel, CourseNumber and CourseDescription form fields are automatically entered into the correspondingly named database fields.
If you look below the DBINSERT tag within the template you will see text and standard HTML markup commands. After completing the insert specified with the DBINSERT command Cold Fusion sends this text back to the client browser which submitted the form.
This lesson illustrates the workings of a simple DBML template file. Templates contain a mix of DBML database tags (which are processed by Cold Fusion) and standard HTML tags and text (which are sent back to the browser).
In the following lesson you will learn how to use DBML tags to dynamically generate HTML tags and text to be sent back to the browser.
You should now proceed to Lesson 2 - Querying for Data.
<!--- Insert the data into the table 'CourseList' --->
<DBINSERT DATASOURCE="CF Examples" TABLENAME="CourseList">
<!--- Show the user a brief message indicating that the
insert was successful --->
<HTML>
<HEAD>
<TITLE>Lesson 1 - Inserting Data</TITLE>
</HEAD>
<BODY>
<H2>New Course Entered into Database</H2>
<P>You just entered a new course into the <I>CourseList</I> table.
The fields CourseName, Department_ID, CourseLevel, CourseNumber
and CourseDescription were populated by data you entered in the form.
<P>
<A HREF="/cfstand/tutorial/step1a.htm">
Go Back to Lesson 1 - Inserting Data</A>
<P>
<HR>
</BODY>
</HTML>