COMP 1230 Lab 2
Topics and learning objectives!
1. Conditionals
2. Loops
3. Alternative syntax for control structures
How to submit!
Create a new directory called `lab02` in your GBLearn account at `~/public_html/labs/lab02/` and
upload your task files to this folder.
Due date is 8pm on the day of the lab.
Task Description
The aim of this lab is to create a form, and then use conditionals and loops to dynamically generate
some content for the second page. Follow the steps below.
1. Create a page (e.g., called `page1.php`), with a form that asks the user to enter a name, and to
choose their favourite colour from a dropdown list.
i. Hint: refer to your work in Lab 1 as a reminder of how to make a form!
ii. When submitted, the form should redirect to a second page (e.g., called `page2.php`).
iii. The form can be submitted using a GET or POST method (your choice).
iv. You should use PHP to create an array containing the colour options, and a for loop to
iterate over the array to create the dropdown list.
The colours in the list are up to you. As a suggestion, you can use “blue”, “red” and “green”.
2. On the second page, use the appropriate superglobal variable to check what the user has
submitted for their name and colour. Use an if/elseif/else condition to check the user’s colour
i. If they chose “red”, output a message saying “That’s my favourite colour too!”
ii. If they chose “blue”, output a message saying “I hate that colour!”
iii. If they chose anything else, output a message saying “That’s a nice colour”
CONTINUED ON NEXT PAGE
Group(s): 80645 1/2
COMP 1230 Lab 2
3. The for loop and if statements in above two steps can be completed in one of two styles:
i. Traditional, using curly braces, e.g.,
$i