CP311 - Internet Programming and Applications II

Examination Answers


QUESTION ONE

Write PHP functions to accomplish each of the following tasks. Assume MySQL database server has been installed on the local machine and the improved version of php has been used.

i. Connect to the server with username root and password cive. (3 Marks)

ii. Select a database called CP311 to be used for queries. (2 Marks)

iii. Execute a query to select all rows and columns from the table called users. (4 Marks)

iv. Get the next row from a result set row. Close the database connection. (4 Marks)


QUESTION TWO

Root element real-estate will contain a sequence of sub-elements agencies, owners, properties and flats, all with an empty content.

i. Create an XML document for the above information (5 Marks)

ii. Create an internal DTD for the XML document in (i). Ensure its validity. (5 Marks)

iii. Move the DTD in (ii) to an external file and validate the XML document again. (3 Marks)


QUESTION THREE

Given the XML document below, define a DTD that validates Document 1. (5 Marks)

Document 1:

<?xml version="1.0" encoding="UTF-8"?>
<student>
    <firstName>Luca</firstName>
    <lastName>Rossi</lastName>
    <id>281283</id>
    <plan>
        <courses year="3">
            <course>
                <name>BSc.Computer Science</name>
                <shortName>BSc.CS</shortName>
                <record>
                    <grade>85</grade>
                    <date>13/06/2021</date>
                </record>
            </course>
            <course>
                <name>BSc.Business Information System</name>
                <shortName>BIS</shortName>
            </course>
        </courses>
    </plan>
</student>

QUESTION FOUR

Explain the Bootstrap modal code below: (5 Marks)

<div class="modal fade" id="ModalExample" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">See more of this awesome website by logging in</h4>
            </div>
            <div class="modal-body">
                <p class="lead text-xs-center">Create account or Sign in</p>
            </div>
            <div class="modal-footer">
                <!-- Empty footer -->
            </div>
        </div>
    </div>
</div>

QUESTION FIVE

Write a PHP script to print configuration info and version. (2 Marks)


QUESTION SIX

Explain the differences between echo and print in PHP. (3 Marks)


QUESTION SEVEN

Explain the difference between include() and require() in PHP. (3 Marks)


QUESTION EIGHT

What is the reason for writing at the beginning of an HTML page? (2 Marks)


QUESTION NINE

Which HTML tag is used to produce a horizontal line? (1 Mark)


QUESTION TEN

HTTP is a stateless protocol. Explain. (2 Marks)


QUESTION ELEVEN

Explain two ways of introducing state in the HTTP protocol. (4 Marks)


QUESTION TWELVE

Explain the difference between unset() and session_destroy() in PHP. (2 Marks)


QUESTION THIRTEEN

Explain how to use the setcookie() function correctly in PHP with an example. (3 Marks)


QUESTION FOURTEEN

Write PHP code to display all users sorted by firstname in descending order. (4 Marks)


QUESTION FIFTEEN

Write PHP code to print all users whose last name starts with the letter “A”. (4 Marks)


QUESTION SIXTEEN

Write a JavaScript function to validate an email address. (3 Marks)


QUESTION SEVENTEEN

Write a JavaScript function to validate a password with the following requirements:

  • At least 8 characters long
  • At least one uppercase letter
  • At least one lowercase letter
  • At least one number
  • At least one special character (!@#$%^&*) (5 Marks)

QUESTION EIGHTEEN

Write PHP code to count page visits using sessions. (3 Marks)


QUESTION NINETEEN

Write PHP code to count page visits using cookies. (4 Marks)


QUESTION TWENTY

Which HTML tag is used to insert the copyright symbol? (1 Mark)


QUESTION TWENTY-ONE

Explain the difference between POST method and GET method in HTML forms. (3 Marks)


QUESTION TWENTY-TWO

Explain the difference between _FILES[‘user_file’][‘tmp_name’] in PHP file uploads. (2 Marks)


QUESTION TWENTY-THREE

How can we capture an error during uploading of files in PHP? (3 Marks)


QUESTION TWENTY-FOUR

How can we change the maximum size of a file to be uploaded in PHP? (2 Marks)


QUESTION TWENTY-FIVE

Write a JavaScript function to validate that a field has exactly 24 numbers. (2 Marks)


QUESTION TWENTY-SIX

Write a PHP script to add two numbers using an HTML form. (3 Marks)


QUESTION TWENTY-SEVEN

Write PHP code to convert an array to a string. (2 Marks)


QUESTION TWENTY-EIGHT

Write PHP code to create and display a cookie. (3 Marks)


QUESTION TWENTY-NINE

Write PHP code to check if cookies are enabled. (2 Marks)


QUESTION THIRTY

Write PHP code to delete a cookie. (2 Marks)


QUESTION THIRTY-ONE

Write PHP code to start a session and create session variables. (2 Marks)


QUESTION THIRTY-TWO

Write PHP code to retrieve and display session variables. (2 Marks)


QUESTION THIRTY-THREE

Write PHP code to destroy a session. (2 Marks)


QUESTION THIRTY-FOUR

What are conventional web applications? (2 Marks)


QUESTION THIRTY-FIVE

What is a rich user interface (UI)? (2 Marks)


QUESTION THIRTY-SIX

What are the issues of conventional web applications? (4 Marks)


QUESTION THIRTY-SEVEN

What are Rich Internet Applications (RIAs)? (2 Marks)


QUESTION THIRTY-EIGHT

List some Rich Internet Application (RIA) technologies. (3 Marks)


QUESTION THIRTY-NINE

What is AJAX and what does it stand for? (2 Marks)


QUESTION FORTY

List some real-life examples of AJAX applications. (2 Marks)


QUESTION FORTY-ONE

List some usage cases for AJAX. (3 Marks)


QUESTION FORTY-TWO

List the technologies used in AJAX. (3 Marks)


QUESTION FORTY-THREE

What is XMLHttpRequest (XHR)? (2 Marks)


QUESTION FORTY-FOUR

List and explain the XMLHttpRequest (XHR) methods. (4 Marks)


QUESTION FORTY-FIVE

List and explain the XMLHttpRequest properties. (5 Marks)


QUESTION FORTY-SIX

List the steps of Ajax operation. (4 Marks)


QUESTION FORTY-SEVEN

Write a PHP function to connect to a MySQL database using MySQLi. (3 Marks)


QUESTION FORTY-EIGHT

Write a PHP function to select a database. (2 Marks)


QUESTION FORTY-NINE

Write PHP code to execute a query and fetch all results. (4 Marks)


QUESTION FIFTY

Write PHP code to close a database connection. (1 Mark)


End of Examination Answers