CP311 - Internet Programming and Applications II

Practical Examples and Solutions


AJAX with MySQL Example

Step One: Create a MySQL Database and Users Table (Database Setup)


Step Two: Create an HTML Interface (index.html) (Frontend Form)


Step Three: Create a PHP File to Process Form Data (process.php) (Server-side Processing)


Step Four: Create a JavaScript File to Handle AJAX (script.js) (AJAX Request Handling)


File Upload in PHP

Question: When dealing with files uploaded through HTTP, PHP stores references to them in the super global array. These files must be processed or moved from their temporary location during the lifetime of the PHP script execution or they will be automatically deleted. Write a PHP script to upload a file to a server. (10 Marks)


Session Cookies in PHP

Question: If no expiration time is explicitly set for cookies, what happens? (3 Marks)


Default Parameter Values in Functions

Question: Under what circumstance it is impossible to assign a default value to a parameter while declaring a function? (5 Marks)


JSON Format Overview

Question: i. Overview of JSON format (what is it, why do we need it, how to create objects in JSON, what is the structure of JSON, JSON and Arrays etc). ii. Using codes, show the similarities between JSON and XML. iii. Using codes, show how you can convert JSON string to array of JSON objects using JavaScript. iv. Using codes, show how you can convert XML data into JSON using PHP. (15 Marks)


JSON and JavaScript Objects

Question: i. Introduction to JSON. ii. Explore JavaScript Objects (what is JS Objects, how can you Display JS objects in browsers, feel free to use DOM). iii. How to use JSON Objects (show how JSON can be used to fetch data from the web server and display in a web browser). iv. JSON stringify and Parse methods (With Examples show how these two methods works) (15 Marks)


Simple Calculator Interface

Question: Create user interface for a simple calculator. The Interface should have a title (Simple calculator), Buttons for simple mathematical operations (+,-,*,/), icon, Button to clear the calculator, Edit Texts(numbers) for accepting the user inputs, Text View for displaying the answer, a nice background color. (10 Marks)


Address Book XML with DTD

Question: A simple address book. One wishes to design an address book in XML. For each entry of the address book, one wants to store the following information:

  • The person name
  • Home address
  • Telephone number (can be more just one)
  • E-mail address (it can be more e-mail addresses)
  • Birth date

To do list:

  1. Write a DTD for the address book.
  2. Write a valid XML file with at least two entries that must illustrate all the possibilities of writing data.
  3. Put all in a file and save as addressBook.xml. (10 Marks)

Car Details XML

Question One: Create a well-formed XML document containing details of a car like: id, company name, model, engine and mileage. (5 Marks)


Question Two: Create a valid XML document containing details of a car like: id, company name, model, engine and mileage using DTD. (5 Marks)


Student Grade Program

Question One: Write a program to check student grade based on marks Conditions:

  • If marks are 60% or more, grade will be First Division.
  • If marks between 45% to 59%, grade will be Second Division.
  • If marks between 33% to 44%, grade will be Third Division.
  • If marks are less than 33%, student will be Fail. (5 Marks)

Day of the Week Program

Question Two: Write a program to show day of the week (for example: Monday) based on numbers using switch/case statements. Conditions:

  • You can pass 1 to 7 number in switch.
  • Day 1 will be considered as Monday.
  • If number is not between 1 to 7, show invalid number in default. (5 Marks)

Array to String Conversion

Question Three: Write a PHP program that converts Array to String. Instructions:

  • Create a form that accept name as well as colors.
  • After submission, form data will be sent to another page.
  • Display selected colors (as a list) and user name.
  • Note: User name & colors selection is mandatory. (10 Marks)

Factorial Using Recursive Function

Question One: Write a PHP program to find factorial of a number using recursive function. (5 Marks)


Simple Calculator with Switch Case

Question Two: Write a simple calculator program in PHP using switch case Operations:

  • Addition
  • Subtraction
  • Multiplication
  • Division (5 Marks)

XML Student Web Service

Question: XML plays an important role in the current world of web development. It is completely beneficial for those who want to use web technology to distribute information across the web. You have been asked to write a web application that will read data from the web service in XML file and display them in a web browser.

Step One: Create a web service in xml format. The XML web service should contain information of the students such as: Students first name, last name, Reg#, Age, Gender, Courses, and Program. (5 Marks)


Step Two: Write the PHP code that will read the XML document and display the results in a web browser. (5 Marks)


End of Practical Examples and Solutions