Inserting the Data
Inserting the Data
- With Dreamweaver open, create a ColdFusion template named insert.cfm in the same folder as your SWF and HTML file.
- Switch to Code view.
- Create a
- Enter myQuiz for the
datasourceattribute. You defined the data source in the previous section.
- Enter insertData for the name attribute, to name your query.
- 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)
<cfif IsDefined("FORM.Total") AND #FORM.Total# NEQ "">
<cfif IsDefined("FORM.correct") AND #FORM.correct# NEQ "">
<cfif IsDefined("FORM.Accuracy") AND #FORM.Accuracy# NEQ "">
<cfif IsDefined("FORM.Name") AND #FORM.Name# NEQ "">
<cfif IsDefined("FORM.Email") AND #FORM.Email# NEQ "">
Thank you for participating in this survey. <br />
This window will close automatically.
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:
- 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.)
- 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.
- Open your database to see the scoring results.