CP311 - Internet Programming and Applications II

Employee Management System


Question: iv) Display employee information in a tabular format and provide a hyperlink to update that employee’s information. When the user clicks Edit Info, the employee’s information should be updated. (5 Marks)


i) Display the employee information in tabular format: (3 Marks)


ii) HTML form to insert employee details into the database using Bootstrap: (5 Marks)


iii) HTML form with dropdown box filled with employee numbers: (3 Marks)


HTML Validation

Question: The HTML document below won’t validate and would generate errors and warnings in the W3C validator. However it is possible to make 5 modifications to the HTML to make it pass validation.

Each validation may result in multiple text “changes” to the HTML document, but it is considered one modification because it is addressing the same root problem. Indicate the 5 modifications we need in order to make it pass validation.

<!DOCTYPE html>
<head>
<html>Welcome to college of Informatics and Virtual Education</h1>
<link src="mypage.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<p>For Department of computer science and Engineering</p>
<ul>
<li> Bsc. In computer Science</li>
<li> Bsc. In Software Engineering</li>
</ul>
For Department of Electronics and Telecommunication Engineering
<ul>
<li> Bsc. In Telecommunication Engineering</li>
<li> Diploma in Telecommunication</li>
<li> Diploma in Computer Networks</li>
</ul>
</body>
<!DOCTYPE html>

(10 Marks)


Form Validation with JavaScript

Question: Given the HTML file below with a form captioned “Registration Form”. Write an external JavaScript file and name it CS312.js which will do the following:

i) modify the given HTML file by providing a link to the external JavaScript. ii) if the user tries to submit the form with one of the fields empty, an alert should be raised telling him/her to fill the field. iii) if the user tries to submit the form with invalid email or password, an alert should be raised telling him/her to fill the form with valid data. iv) modify the given HTML file by calling a JavaScript function that validates the HTML form. (10 Marks)


Page View Counter with Cookies

Question: Make a web page that uses a cookie to keep track of how many times a user has viewed the page. The first time a particular user looks at the page, it should print something like “Number of views:1” The second time the user looks at the page, it should print “Number of views: 2” and so on. (5 Marks)


Database and Table Creation

Question: A) Write an SQL script to create a table called users in a database, with the following fields (assume the specific database has already been accessed).

  • id, which is the primary key and value is provided by the database server.
  • Username, which has an appropriate string format.
  • password, with a format specific for the SHA encryption algorithm.
  • reg_date, with an appropriate date format. (5 Marks)

B) Which PHP functions are used to achieve the following with a MySQL database server on the local machine.

i) connect the server with username root and password carrot2go. ii) select a database called ad006 to be used for queries. (4 Marks)


PHP Configuration and Array Operations

Question: A) write a PHP script to get the PHP version and configuration information. B) what is the difference between echo and print. C) Describe the difference between client/server interactions in traditional web applications and client/server interactions in Ajax web applications. D) Consider the following associative array:

<?php
$ManU = array (
    'Rashford' => '25',
    'Pogba' => '24',
    'Degea' => '22',
    'Martial' => '25'
);
?>

i) write a PHP script to add new element with the key “Wan-Bisaka” and value “24”. ii) write PHP code to remove the element with the key “Pogba”. (10 Marks)


File Upload and JavaScript Functions

Question: A) With the help of PHP and XHTML write script that can be used to upload and extract a zipped file in the server. B) write a JavaScript function that will make sure the form text box contain numbers only, in case user type a character which is not a number the function must delete the number. C) using XHTML and JavaScript code, build a web page with two text boxes. Make it so that when you change the USD field, the proper conversion to Tsh is written into the Tsh. Box and vise versa. [1 USD is 1700Tsh.] A sample output is shown below:

Currency converter

USDTsh.
11700
(15 Marks)

Credit Limit Checker

Question: Develop a JavaScript program that will determine whether a department-store customer has exceeded the credit limit on charge account. For each customer, the following facts are available.

a) account number. b) balance at the beginning of the month. (5 Marks)


PHP, JavaScript, and MySQL Tips

Question: A) how can we get the browser properties using PHP. B) how can we increase the execution time of a PHP script. C) how can we optimize or increase the speed of MySQL select query. D) how can I know that a variable is a number or not using a JavaScript. E) how can we send email using JavaScript. F) how can we know the number of days between two given dates using PHP. (12 Marks)


PHP Variable Variable and Array Access

Question: A) what is the output of the following script:

<?
$a="b";
$b=20;
$a=11;
echo $$a;
?>

B) what will be the output of the following script:

<?php
define('FOO',10);
$array = array(10 => FOO, 'FOO' => 20);
print $array[$array[FOO] + $array['FOO']];
?>

(4 Marks)


DTD, CSS, JavaScript Objects, and XML Advantages

Question: i) what is the document type definition (DTD)? What DTD do you generally use? Why? What are the pros and cons. ii) write a snippet of CSS that will display a paragraph in blue in older browser, red in newer browser, green in IE6, and black in IE7. iii) with the help of code segment, describe three different ways that can be used to create a JavaScript object. iv) explain two advantages of using XML. (15 Marks)


PHP String Functions and Array Storage

Question: a) what is the value displayed when the following is executed:

<?php
$email = 'cs312@gmail.com';
$user = strstr($email,'@',true);
echo $user;
?>

b) what is the output of the following php script:

<?php
$val1 = 42;
if (is_numeric($val1)){
    echo "Integer";
} else{
    echo "Not Integer";
}
$val2 = '42';
if (is_numeric($val2)){
    echo "Integer";
} else{
    echo "Not Integer";
}
?>

c) what happens when a form submitted to a php script contains two elements with the same name? d) how would you store an array in a cookie? e) by default, php stores session data in? (10 Marks)


AJAX Questions

Question One: With example explain how AJAX works. (5 Marks)


Question Two: Write a code to show how to fetch and display data using AJAX with PHP and Database. (5 Marks)


Question Three: Write a code to show how to fetch and display data using AJAX with JQuery. (5 Marks)


Question Four: Write a code to show how to fetch and display data using AJAX with XML. (5 Marks)


File Filtering with PHP

Question: Write the PHP code for a web page that filters lines of text from a file. The page should contain a short form with a text box where the user can type a word. The page also displays the current contents of the file text.txt as a pre-formatted block. The form submits back to the same page, filter.php as a POST request when the word is submitted. Your code should examine the contents of text.txt and remove any lines from the file that contain the given word. Case-insensitively. Write the changes to the file so that any future viewings of the page will see the changes. You can write just the code dealing with the page’s body. You don’t need to output a head section or a complete page.

Match the exact word, not other words than contain it as a substring for example, if user submits the word “me” you would filter out lines containing the word “me” but not lines that contain a word such as “men” or “game”.

If the user makes a POST but somehow does not submit the query parameter for the word, or if the word they submit does not consist entirely of upper/lowercase letters, issue an HTTP 400 error and do not display the rest of the page. Use the browser’s default styling. (10 Marks)


AJAX Database Access Step-by-Step

Question: AJAX allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page. Step by Step show how you can access information from the database using AJAX and PHP.

Step One: Create a table called Users with information (Id, Name, Email, Gender and Age). Step Two: Create an interface where user can insert information to the users table. Step Three: Create a Php file that will process the information entered by the user through the interface. Step Four: Create a function that will receive data sent from the server and will update the section (eg. Div etc) of the same web page you have created in Step Two. (10 Marks)


PHP Programs: Factorial, Calculator, Array to String

QUESTION ONE: Write a PHP program to find factorial of a number using recursive function. What is Recursive Function? (5 Marks)


QUESTION TWO: Write a simple calculator program in PHP using switch case Operations:

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

QUESTION THREE: Write a PHP program that convert 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 select colors (as a list) and user name.
  • Note: User name & colors selection is mandatory. (10 Marks)