The aim of this lab is for you to start modifying and writing simple PHP applications. Assistance will be given in labs.
Download the zipped archive details.zip containing the personal details application discussed in lectures onto your PC and unzip it.
detailsdirectory to dwarf so you can run the application from your own file system there, using a URL of the form
http://dwarf.ict.griffith.edu.au/~sxxxxxxx/wp/labs/lab2/details/get_details.html. Look at the URL used to call the PHP script
show_details.php; it should have the form
show_details.phpdirectly by typing a URL with a nonempty query part, as indicated immediately above, without entering data into the form at all.
Download the zipped archive factorise.zip
containing the factorisation
example discussed in lectures onto your PC, unzip it, and
transfer the resulting directory to a directory
.../wp/labs/lab2/factorise/ on dwarf, and test that it works.
The next step is to edit this factoristion example.
(Some members of the teaching team recommend the use of the NetBeans IDE to edit PHP (and Smarty) scripts. An useful feature of NetBeans is that it allows you to work on scripts that resides on a remote server. How this works is that you need to first specify the remote server address and directory. Then NetBeans makes a copy of the files in that directory to your local computer, and creates a NetBeans project. Whenever, you run the project, NetBeans will upload the files to the server, and run the scripts from the server. If you would like to use this handy feature, follow the link to Setup NetBeans Remote Connection. )
Modify the script
factorise.php so that it behaves like
factorisation example. In particular, note the following
features of this improved example:
abc) or out-of-range (e.g., 1) number is entered, an appropriate error message is displayed on the same page instead of the factorisation.
Hint 1. If the user input is invalid, instead of printing an
error message immediately, assign the error message to a PHP
$error, say. Later, if the variable
empty, compute the number's factors and print the factorisation as
otherwise print the value of
Hint 2. To display the value of variable
the form's input field, use the
value attribute as follows:
<input type="text" name="number" value="<?= $number ?>" >
Download the zipped archive assoc.zip
containing the Prime
Ministers database example discussed in lectures onto your PC,
unzip it, and transfer the resulting directory to a directory
.../wp/labs/lab2/assoc/ on dwarf, and test that it works. (The
assoc is used because information about each Prime
Minister is stored in an associative array.)
Modify the form in
so that it contains a single text field.
Modify the PHP script
results.php and the function
defs.php so that it takes a single query
from the text field and shows all Prime Ministers whose name or year
or state matches that query.
Hint 3. Loop through the list of Prime Pinisters once only. Test whether each Prime Minister has a name or year or state that matches the given query, and if so add the Prime Minister to an initially empty result list. Finally, return the result list.
Remember to give every new directory permissions 705 and every new HTML or PHP file permissions 604.
Note that you can execute a PHP script
from the (dwarf) command line by
php script.php". This is very useful for
debugging, particularly for finding PHP syntax errors.
Demonstrate working PHP solutions to Exercises 3 and 4 above. All HTML used or generated by your solution should be valid HTML5.
If you have successfully submitted the milestone and would like to learn additional skills, further modify your solution to Exercise 3 by appending each factorisation (12 = 2 . 2 . 3) to a text file so you can display the list of all previous factorisations below the current one. This extension is not required.