CogSci 3 -PHP - Part 2
Due WEDNESDAY, December 2nd, 2009 11:59pm
-Extra time has been granted due to Thanksgiving break! :-)

Goals

  1. Create a COGS3 Quiz using <form> ... </form> in XHTML. (You should have already done this.)
  2. Publish the Quiz on the web and have students take the quiz.
  3. Using PHP, the quiz will be corrected and statistical infomation is gathered.

Create the PHP script that will grade the quiz.

Using your text editor, create a file called: grade-quiz-cg3xaa.php (use your account number!) Use Notepad++ (or TACO on the Mac) , not Wordpad!

The file should also be in your public_html directory. You will be testing it from the server. So, if you are working from home, be sure to FTP (use FileZilla or FuGu) (upload) the file everytime it is modified.

Using the echo() or print() functions in PHP.

Time to test! save your file: grade-quiz-cg3xaa.php in your public_html directory on the icogsci1 server.

You should see your Part 1 of the assignment appear. If you were to take the quiz at this point, nothing should happen.

Submit the form... Click on the "Grade Quiz Now" button.

If you have gotten this far, then continue. If you have not gotten this far, then look to make sure that you have the correct file names (both in your html document and your php document.)

Troubleshooting

We're giving you the PHP code to enter. However, it is possible to get syntax errors because you've mis-entered something; this will keep your .php script from working. So consider doing the following:

Ready to continue... remember, when you make changes at home -- to re-FTP the document back to the server.

Recall, the following....

$_POST[.....] is a PHP superglobal variable. The $_POST variable is where PHP stores all of the variables and values sent via the post method (see red lines below.). (The same applies to the $_GET superglobal variable -- which we are not using in this assignment.)

$_POST[ ] is an array, and the index is the name value associated with the input element (see yellow and green lines in figure below.)

The purple line shows the relationship to the PHP filename called by the action attribute of the form element of the html document and the PHP document.

Now you are ready to grade the quiz -- but how does one know what was selected?

First, for each question, one needs to figure out which radio button was selected. Consider the logic depicted in the figure below:

A closer look at Question 1...

Using the switch statement in PHP to implement the series of conditionals.

Once you have coded a switch statement for each of the questions, test your program to make sure that everything is working.
Once it is, then you are ready to tackle part 3.


Original Šopyright 2006 November 21, 2006 Mary ET Boyle
Modified November 2007 mrw