ITU07427 - Lab Worksheet
ITU07427 - Lab Worksheet
DEPARTMENT OF INFORMATICS
LAB WORKSHEET
Introduction
This lab is intended to equip students with programming principles for developing web-
based applications.
(i) Use web techniques in configuring a web server and database server
References
• Lecture handouts
• Deitel, H. M. & Deitel, P. J. (2011). Internet & World Wide Web: How to Program.
5th Ed. Upper Saddle River, NJ: Pearson Education
• Welling, L. & Thomson, L. (2016). PHP and MySQL Web Development. 5th Ed.
Boston, MA: Addison-Wesley Professional
• Cross, M. (2011). Developer's Guide to Web Application Security. Rockland, MA:
Page 1 of 7
Syngress Publishing, Inc.
Practical Questions
Topics: Introduction to PHP and PHP Operators
1. Modify the PHP first script so that the script displays the string “Welcome to
Advanced Web Design” in a web browser.
2. Write a PHP script which calculates and displays the sum of two numbers in a
web browser.
3. Write a PHP script that calculates and prints the area and perimeter of a
rectangle in a web browser.
4. Write a PHP script that outputs “My name is $name” where $name is a variable
that stores your actual name.
<?php
$num = 10;
echo 'What is her age? \n She is $num years old;
?>
6. Write a PHP script named area.php that calculates and displays an area of a
circle in a web browser.
Page 2 of 7
7. Write a PHP script that obtains two numbers from a user, calculates the sum of
these numbers and displays the result in a web browser [Note: A script requires
HTML/PHP form].
9. Write a PHP script that accepts two numbers, divides the first number by the
second number and prints the result in a web browser.
10. Write a PHP script that asks the user to enter two numbers, obtains the numbers
from the user, and then prints in a web browser the larger number followed by
the words “is larger.” If the numbers are equal, print the message “These
numbers are equal.”
11. Write a PHP script that inputs three different numbers from the keyboard, then
prints the sum, the average, the product, the smallest and the largest of these
numbers in a web browser.
12. Use Table 1 which shows numerical score ranges and their respective grades to
write a PHP script that checks the student’s score and prints the student’s grade
in a web browser.
81 – 100 A
61 – 80 B
41 – 60 C
21 – 40 D
Page 3 of 7
0 – 20 F
<?php
$team = "manu";
switch ($team) {
case "manu":
echo "I love Manchester United";
break;
case "arsenal":
echo "I love Arsenal";
break;
case "manc":
echo "I love Manchester City";
break;
default:
echo "I do not like football at all";
}
?>
14. Write a PHP script that displays even numbers between 1 and 100 inclusive in a
web browser.
15. Write a PHP script that calculates the sum of the first 200 counting integers and
displays the result in a web browser.
16. Write a PHP script that calculates the squares and cubes of the numbers from 0
to 10 and uses tabs to print the following table of values in Figure 1:
Page 4 of 7
Figure 1: Table of values
18. Define a function area which calculates the area of the circle. Call the function
and display the area calculated by the function in a web browser.
19. Write a PHP script that accepts input of two numbers. The script contains
function add for performing the addition of two numbers; function subtract for
performing subtraction of the second number from the first number; function
multiply for performing multiplication of the two numbers and function divide for
performing division of two numbers. The script should also give the user an
option of performing one of the operations above and displaying the result in a
web browser.
20. Given the array, $fruits = array (“apple", "orange", "banana"), write a PHP script
that displays all the array elements of the array $fruits in a web browser.
21. Write a PHP script that calculates the sum and average of all array elements,
$numbers=array (4, 8, 16, 32, 64) and prints the sum and average in a web
browser.
Topic: SQL
22. The university database consists of two tables – student and user. The student
table consists of four columns that stand for each student’s registration number,
Page 5 of 7
full name, department and date of birth. Write SQL statements to perform the
following activities:
(a) Retrieve the list of all employees and their respective departments
(b) Retrieve the birth date and address of the employee(s) whose name is
‘John B. Smith’.
(c) Retrieve the name and address of all employees who work for the
‘Research’ department.
(d) Select all EMPLOYEE Ssns
(e) Select all combinations of EMPLOYEE Ssn and DEPARTMENT Dname in
the database.
(f) Retrieve the total number of employees in the company
(g) Retrieve the total number of employees in the ‘Research’ department
(h) For each department, retrieve the department number and the number of
employees in the department.
Page 6 of 7
Topics: Connecting PHP to MySQL, and Sessions
24. Write a PHP script that retrieves data from the student table of the university
database as shown in Figure 2.
25. Write a PHP script that obtains a URL and its description from a user and stores
the information in a database using MySQL. Create and run a SQL script with a
database named URL and a table named Urltable. The first field of the table
should contain an actual URL, and the second, which is named Description,
should contain a description of the URL. Use www.deitel.com as the first URL,
and input Cool site! as its description. The second URL should be www.php.net,
and the description should be The official PHP site. After each new URL is
submitted, print the contents of the database in a table.
26. Write a PHP script that creates session variables and uses them to authenticate
a user to log into a web-based information system using a username and
password.
27. Write a PHP script that destroys session variables in question 26.
Page 7 of 7