PHP Lab

Take a look and try each of the following PHP scripts. (The text of the scripts are provided in text files).

  1. Simple example which demonstrates that several PHP scripts can be embedded in a single web page and shows how to do output from PHP:    hello.php    hello.txt
  2. This script demonstrates comments, iteration, and selection in PHP:  loop.php    loop.txt
  3. A pure HTML form passes scalars to a PHP processing script:  form.html    form.txt    process.txt
  4. A script demonstrates passing values within an array:  form2.php    form2.txt    process2.txt

  1. Write a pair of web pages with embedded PHP scripts.  The first PHP script should generate a form which allows the user to input 10 numbers.  When the form's submit button is pressed, the 10 numbers should be sent to the second PHP script as an array.  The second script should display the largest number in the array and the average of the 10 numbers.
     
  2. Design a form which implements a two or three question multiple choice test (Use radio boxes to select answers --- see The Bare Bones Guide to HTML. The user should input their name in a text box at the top of the form. Write a PHP script to grade the test, greet the user by name, and print the number of correct answers. Use arrays to pass the selected answers to the PHP script and to hold the list of correct answers. Hint: your radio box tags will need to be similar to:
    <input type=radio name='ans[0]' value='A'>
    
    Notice how the array used to pass the answers from the form to the processing script is indexed.