sample php code for multiple-choice quiz (without comments)

about the sample php code for a multiple-choice quiz


• The comments on the sample code for a multiple choice quiz are aimed at flesl.net users who want to write their own interactive multiple-choice quizzes but whose lack of coding skill prevents them from doing so. In other words, they’re aimed at anyone in a similar position to my own at the time I began writing interactive quizzes for flesl.net. (There are links to those quizzes—highlighted in green—in the Grammar Directory)

• When I started work, I had little understanding of how html forms are used, in combination with php, to make interactive pages. In fact, I knew almost nothing about php and had only a very elementary knowledge of html.

• I began by working with online tutorials and found some useful ones; [two are listed in the “Technical” section of the Links Directory.] In the end, however, I found that I couldn’t learn enough from these tutorials to do what I wanted to do. One reason for this was that they were intended for "newbies" who wanted to make online forms that had the same use as everyday paper forms—submitting information, registering, ordering merchandise, etcetera.

• I wanted to use html forms to do something quite different, and that meant it was important to understand, from the start, that forms can be used to allow a page to send information to itself. This method of using forms was not emphasized in the tutorials I looked at. The code samples I found were almost intended for sending information from one page to another.

• Although this is, typically, not mentioned at an elementary level, it is in fact necessary for anyone writing any sort of form to understand how a page can send information to itself. This is because, to be useful, all forms have to be “sticky.” A form is sticky, if when a user attempts to submit it without having provided all the necessary information, it is returned with the places where more information is required highlighted in some way and with the already-submitted information still visible.

• The technique of writing a web page that sends information, “stickily,” to itself is easy to understand once it has been well explained and illustrated with clear code samples. Someone with more advanced general programming skills could, no doubt, have picked all this up from the tutorials I studied, but I spent quite a long time struggling to make progress without getting very far.

• I was finally rescued by discovering online, a free chapter of a book by Larry Ullman, PHP for the World Wide Web. It was by reading that chapter that I learnt what I needed to know to write interactive quizzes. After reading the free chapter I bought the book and worked my way systematically through most of it. It was a fruitful and enjoyable experience and I strongly recommend Ullman’s book to anyone who is starting out with php.

• Apart from getting a grasp of the principles discussed above I also learned, reading Larry Ullman’s book, how to use php code to sweep repeatedly through a form, returning an altered version to the user each time. The “basic quiz code” is an example of this approach: when the page is opened the script runs through each of the questions and prints out a blank quiz. Whenever the “submit” button is clicked the script runs through the questions again checking to see if they have all been answered. If it finds any unanswered questions, the unfinished quiz reappears, and the user is told that it has to be completed. The script will continue running through all the questions each time the “submit” button is clicked until, finally, they have all been answered. Then the “submit” button disappears and the user’s score is displayed.

-fl, 08.07