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.
cfquery tag. datasource attribute. You defined the data source in the previous section.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: