switch, forms and the Add Term page
Answers are for parents and teachers.
1
What does this print? $n = 3; switch ($n) { case 1: echo "a"; break; case 3: echo "c"; case 4: echo "d"; break; default: echo "z"; }
cd. Case 3 prints c, falls through into case 4, prints d, and break stops it.
2
Rewrite with stacked cases so that the numbers 6 and 7 print “weekend” and 1 to 5 print “school day”.
case 1: case 2: case 3: case 4: case 5: echo "school day"; break; case 6: case 7: echo "weekend"; break;
3
Choose GET or POST and give a reason: (a) a search box for the dictionary, (b) a form that uploads a picture, (c) a form that changes a member’s level.
(a) GET: the address can be saved. (b) POST with multipart/form-data: a file must be sent. (c) POST: it changes data.
4
A form has <input name="title" type="text">. Write the PHP that reads what was typed (the form uses post).
$title = $_POST['title'];
5
Why must the name written in the form match the name used in PHP, letter for letter?
PHP finds the value by that name, and names are case-sensitive.