Showcase and discover digital art at yex

Follow Design Stacks

Subscribe to our free newsletter to get all our latest tutorials and articles delivered directly to your inbox!

Inserting the Data

Inserting the Data

In this step, you set up the document to insert data into the database. This is the document referenced in your form action in the JavaScript.

  1. With Dreamweaver open, create a ColdFusion template named insert.cfm in the same folder as your SWF and HTML file.
  2. Switch to Code view.
  3. Create a cfquery tag.
  4. Enter myQuiz for the datasource attribute. You defined the data source in the previous section.
  5. Enter insertData for the name attribute, to name your query.
  6. After the query in the body, type a thank you message (see below).

Copy and paste the following code snippet into the insert.cfm file:

<!--This query inserts the test scores into the database.  
The INSERT statement specifies the column names.
The VALUES statement specifies the values to insert.
Note that this query uses CFIF statements to determine whether
the field contains a value or is empty (or NULL). -->

<cfquery datasource="myQuiz" name="insertData">
INSERT INTO Captivate (total, correct, accuracy, name, email)
VALUES (
<cfif IsDefined("FORM.Total") AND #FORM.Total# NEQ "">
'#FORM.Total#'
<cfelse>
NULL
</cfif>
,
<cfif IsDefined("FORM.correct") AND #FORM.correct# NEQ "">
#FORM.correct#
<cfelse>
NULL
</cfif>
,
<cfif IsDefined("FORM.Accuracy") AND #FORM.Accuracy# NEQ "">
'#FORM.Accuracy#'
<cfelse>
NULL
</cfif>
,
<cfif IsDefined("FORM.Name") AND #FORM.Name# NEQ "">
'#FORM.Name#'
<cfelse>
NULL
</cfif>
,
<cfif IsDefined("FORM.Email") AND #FORM.Email# NEQ "">
'#FORM.Email#'
<cfelse>
NULL
</cfif>
)
</cfquery>
<html>
<head>
<title>Quiz Results</title>
<meta http-equiv="refresh" content="3;URL=javascript:window.close();">
</head>
<body>
Thank you for participating in this survey. <br />
This window will close automatically.

</body>
</html>

Now, you have created a way to insert information from the quiz into your Microsoft Access database. Test the CFML file with the following steps:

  1. Browse your HTML file in your browser (the URL you will browse your file at will be similar to: http://localhost:8500/Captivate_scoring/myquiz.htm. (Your URL may be different based on where you placed your files in your directory structure and your host server port.)
  2. Take the quiz several times. When the scoring window appears, enter your username and e-mail address and click Submit Your Score. This will enter data into your database. Repeat this step several times by refreshing the HTML file in your browser.
  3. Open your database to see the scoring results.

Comments