PHP Trivia Quiz Application

Verified

Added on  2019/09/16

|1
|801
|380
Practical Assignment
AI Summary
This assignment requires the development of a PHP-based trivia quiz application. The application involves user registration via email, storing the email in a cookie, and presenting a series of five trivia questions. Each question requires the user to identify the artist of a given album title within three attempts. Successful completion of the quiz results in a discount coupon code, also stored in a cookie. The application uses session variables to track the current question, attempts, and album/artist information. The assignment is divided into three parts: a registration page, a trivia question page, and a coupon validation page. The application also includes error handling for incorrect answers and expired attempts. The database connection is to be inserted by the user.
Document Page
1. Create a PHP application to present a trivia quiz to a user. Upon successful completion, a discount code will
be provided. The application should work as follows:
a. The user will register for the quiz by entering their email which will be stored in a cookie that
expires in 14 days.
b. They will then be presented with a series of 5 album titles. They must correctly enter the
corresponding artist name within 3 tries to get credit for the question.
c. If they answer 5 questions correctly before the session expires, then they will be awarded a
coupon code which will be stored in a cookie that expires in 14 days.
d. To redeem the coupon, they must enter the email address and coupon code that matches the
cookies in their browser to get the discount.
e. Session variables will be used to keep track of the current question number, album, artist and
number of tries.
2. Part I: Trivia Quiz registration page
a. Display a form requesting the user email and a submit button labeled Start Quiz.
b. Include instructions that they will have 3 tries to answer each trivia question. There is a 20-minute
time limit. If they successfully answer 5 questions, they will receive a coupon code good for 25%
off their next order.
c. When submitted:
i. Check to see if a cookie called coupon exists. If so, display an error that they have
already completed the quiz.
ii. if not, create a cookie called email and store their email address in it. The cookie should
expire in 14 days. Transfer to the Trivia Questions page.
3. Part II: Trivia Questions page
a. Check to see if a cookie called coupon exists. If so, display the error that they have already
completed the quiz and end the script
b. Check to see if a session variable called questNo exists.
i. If not, create the questNo variable with a value of 1 and another session variable called
tries and set it to 0.
ii. If it exists:
1. if questNo is > 5, then display an error that they have already completed the
quiz and end the script.
2. otherwise add 1 to the tries session variable
c. If tries > 0:
i. Compare the answer from the form to the artist name in the session variable.
ii. if the names match:
1. set the tries variable to 0
2. add 1 to the questNo session variable.
3. if questNo session variable > 5, Create a cookie called coupon with a value of
'save25' that expires in 14 days and display a congratulatory message that they
have completed the quiz and received their discount. Display the discount code
'save25' and tell them it is valid for 14 days.
iii. If the names do not match:
1. add 1 to the tries variable.
2. display an error message that the names do not match
3. If the tries session variable > 3, then delete the email cookie, destroy the
session and display an error: "Sorry you have exceeded your tries" and end the
script.
d. If tries = 0:
i. Generate a random number between 1 and 347.
1. connect to the Chinook database ***(I have access to a local server that you
will not be able to access, please notate in the code where the connection
sequence should be located and I will insert.)***
2. use the random number as the albumId and run a query against the Chinook
database to get the album title from the album table and the corresponding
artist name from the artist table (join on artistId).
3. Store the album title and artist name in 2 session variables.
e. Display the album title in a trivia question form asking the user to enter the artist.
4. Part III: Coupon validation page
a. Normally, this would-be part of a checkout process, so if you completed the lab practice for Comp
4-1 or 4-2, you can add this code to that page. If not, you can just create a simple coupon
validation page that includes this functionality:
i. Create a form with a coupon text field, an email text field and a submit button.
ii. When the user enters a coupon code, check to see if the coupon cookie exists. If so,
compare the coupon code and the email address to the corresponding cookie values.
Display a message telling the user if the code is valid (both values match) or invalid (at
least 1 did not match).
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
[object Object]