Create a PHP application to present a trivia quiz to a user.
Added on - 16 Sep 2019
Trusted by +2 million users,
1000+ happy students everyday
1000+ happy students everyday
Showing pages 1 to 1 of 1 pages
1.Create a PHP application to present a trivia quiz to a user. Upon successful completion, a discount code willbe 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 thatexpires in 14 days.b.They will then be presented with a series of 5 album titles. They must correctly enter thecorresponding 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 acoupon 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 thecookies in their browser to get the discount.e.Session variables will be used to keep track of the current question number, album, artist andnumber of tries.2.Part I: Trivia Quiz registration pagea.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-minutetime 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 havealready completed the quiz.ii.if not, create a cookie called email and store their email address in it. The cookie shouldexpire in 14 days. Transfer to the Trivia Questions page.3.Part II:Trivia Questions pagea.Check to see if a cookie called coupon exists. If so, display the error that they have alreadycompleted the quiz and end the scriptb.Check to see if a session variable calledquestNoexists.i.If not, create thequestNovariable with a value of 1 and another session variable calledtries and set it to 0.ii.If it exists:1.ifquestNois > 5, then display an error that they have already completed thequiz and end the script.2.otherwise add 1 to the tries session variablec.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 02.add 1 to thequestNosession variable.3.ifquestNosession variable > 5,Create a cookie called coupon with a value of'save25' that expires in 14 days and display a congratulatory message that theyhave 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 match3.If the tries session variable > 3, then delete the email cookie, destroy thesession and display an error: "Sorry you have exceeded your tries" and end thescript.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 youwill not be able to access, please notate in the code where the connectionsequence should be located and I will insert.)***2.use the random number as thealbumIdand run a query against the Chinookdatabase to get the album title from the album table and the correspondingartist name from the artist table (join onartistId).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 pagea.Normally, this would-be part of a checkout process, so if you completed the lab practice for Comp4-1 or 4-2, you can add this code to that page. If not, you can just create a simple couponvalidation 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 (atleast 1 did not match).