Browse papers
A

Section A: Long Answer Questions

Attempt any TWO questions.

3 questions·10 marks each
1long10 marks

Explain how PHP handles forms and connects to a MySQL database. Write a PHP script to insert and retrieve student records from a MySQL database.

PHP Form Handling and MySQL Connectivity

How PHP handles forms

When an HTML form is submitted, the browser sends the field data to a PHP script via the HTTP GET or POST method. PHP collects this data into the superglobal arrays $_GET, $_POST, or $_REQUEST. The form's action attribute names the PHP file and the method attribute selects the transfer method.

<form action="student.php" method="post">
  Name: <input type="text" name="name"><br>
  Age:  <input type="text" name="age"><br>
  <input type="submit" name="submit" value="Save">
</form>

Inside student.php the value is read with $_POST['name']. Data should always be validated and sanitised (e.g. trim(), htmlspecialchars(), prepared statements) to prevent injection.

Connecting PHP to MySQL

PHP connects to MySQL using the MySQLi or PDO extension. The steps are: (1) open a connection, (2) run SQL queries, (3) process results, (4) close the connection.

Complete script: insert and retrieve student records

<?php
// 1. Connect to MySQL (host, user, password, database)
$conn = new mysqli("localhost", "root", "", "college");
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// 2. INSERT a record (using a prepared statement to stay safe)
if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $age  = (int)$_POST['age'];
    $stmt = $conn->prepare("INSERT INTO student (name, age) VALUES (?, ?)");
    $stmt->bind_param("si", $name, $age);  // s = string, i = integer
    $stmt->execute();
    echo "New record inserted (id = " . $conn->insert_id . ")<br>";
    $stmt->close();
}

// 3. RETRIEVE and display all records
$result = $conn->query("SELECT id, name, age FROM student");
echo "<table border='1'><tr><th>ID</th><th>Name</th><th>Age</th></tr>";
while ($row = $result->fetch_assoc()) {
    echo "<tr><td>{$row['id']}</td><td>{$row['name']}</td><td>{$row['age']}</td></tr>";
}
echo "</table>";

// 4. Close the connection
$conn->close();
?>

The table is assumed to be created as:

CREATE TABLE student (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50), age INT);

This demonstrates the full cycle: form submission → PHP reads $_POST → MySQLi connection → prepared INSERT → SELECT and display.

phpmysql
2long10 marks

Explain client-side form validation using JavaScript. Write an HTML form with JavaScript to validate a username, password and a checkbox before submission.

Client-Side Form Validation using JavaScript

Client-side validation checks form input in the user's browser before the data is sent to the server. It runs in JavaScript, so errors (empty fields, wrong format, weak password, unticked agreement) are caught instantly without a round-trip to the server.

Advantages

  • Immediate feedback, better user experience.
  • Reduces unnecessary server load and network traffic.

Note: Client-side validation can be bypassed (JavaScript disabled), so it must always be backed up by server-side validation for security.

HTML form with JavaScript validation

<!DOCTYPE html>
<html>
<head>
<script>
function validateForm() {
  var user = document.forms["reg"]["username"].value;
  var pass = document.forms["reg"]["password"].value;
  var agree = document.forms["reg"]["terms"].checked;

  // 1. Username required, at least 4 chars
  if (user.trim() === "") {
    alert("Username is required"); return false;
  }
  if (user.length < 4) {
    alert("Username must be at least 4 characters"); return false;
  }
  // 2. Password required, at least 6 chars
  if (pass.length < 6) {
    alert("Password must be at least 6 characters"); return false;
  }
  // 3. Terms checkbox must be ticked
  if (!agree) {
    alert("You must accept the terms"); return false;
  }
  return true;   // all checks passed -> allow submission
}
</script>
</head>
<body>
<form name="reg" action="submit.php" method="post" onsubmit="return validateForm()">
  Username: <input type="text" name="username"><br>
  Password: <input type="password" name="password"><br>
  <input type="checkbox" name="terms"> I accept the terms<br>
  <input type="submit" value="Register">
</form>
</body>
</html>

The onsubmit="return validateForm()" handler runs the function on submit; returning false cancels submission and shows the alert, while true lets the form proceed.

javascriptform-validation
3long10 marks

Explain the structure of an HTML5 document. Discuss the different ways of applying CSS (inline, internal, external) with examples and explain the CSS box model.

Structure of an HTML5 Document, Applying CSS, and the Box Model

1. Structure of an HTML5 document

An HTML5 page begins with the simplified doctype and a clear structure:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Page Title</title>
</head>
<body>
  <header>...</header>
  <nav>...</nav>
  <main>
    <section>...</section>
    <article>...</article>
  </main>
  <footer>...</footer>
</body>
</html>
  • <!DOCTYPE html> — declares HTML5.
  • <head> — metadata (charset, viewport, title, links to CSS/JS).
  • <body> — visible content.
  • HTML5 adds semantic elements: <header>, <nav>, <main>, <section>, <article>, <aside>, <footer>.

2. Three ways of applying CSS

(a) Inline CSSstyle attribute on a single element (highest priority, hard to reuse):

<p style="color:red; font-size:18px;">Hello</p>

(b) Internal (embedded) CSS — inside a <style> block in the <head>, applies to one page:

<style>
  p { color: blue; text-align: center; }
</style>

(c) External CSS — a separate .css file linked with <link>; best for multi-page sites (reusable, cached):

<link rel="stylesheet" href="styles.css">
/* styles.css */
p { color: green; }

3. The CSS Box Model

Every element is a rectangular box made of four layers, from inside out:

LayerMeaning
ContentThe actual text/image (width × height)
PaddingSpace between content and border
BorderLine surrounding the padding
MarginSpace outside the border, separating from other elements
+-----------------------------+
|          margin             |
|  +-----------------------+  |
|  |       border          |  |
|  |  +-----------------+  |  |
|  |  |    padding      |  |  |
|  |  |  +-----------+  |  |  |
|  |  |  | content   |  |  |  |
|  |  |  +-----------+  |  |  |
|  |  +-----------------+  |  |
|  +-----------------------+  |
+-----------------------------+

Total width = content + left/right padding + left/right border + left/right margin. With box-sizing: border-box, padding and border are included inside the declared width.

htmlcss
B

Section B: Short Answer Questions

Attempt any EIGHT questions.

9 questions·5 marks each
4short5 marks

Explain different types of CSS selectors with examples.

Types of CSS Selectors

A selector targets the HTML element(s) a CSS rule applies to.

SelectorSyntaxExampleTargets
Universal** { margin:0; }All elements
Element (type)tagp { color:blue; }All <p>
Class.name.btn { padding:5px; }Elements with class="btn"
ID#id#nav { width:100%; }The element with id="nav"
Groupa, bh1, h2 { color:red; }Multiple selectors at once
Descendanta bdiv p { ... }<p> inside a <div>
Childa > bul > li { ... }Direct <li> children of <ul>
Attribute[attr]input[type="text"] {...}Elements with that attribute
Pseudo-class:statea:hover { color:green; }Elements in a state
Pseudo-element::partp::first-line {...}Part of an element

Specificity order (low→high): universal < element < class/attribute/pseudo-class < ID < inline style.

css-selectors
5short5 marks

Explain JavaScript data types, operators and control structures with examples.

JavaScript Data Types, Operators and Control Structures

Data types

  • Primitive: Number (10, 3.14), String ("hi"), Boolean (true/false), Undefined, Null, BigInt, Symbol.
  • Non-primitive (reference): Object, Array, Function.

JavaScript is dynamically typedtypeof x returns the current type.

let n = 25;        // number
let s = "CSIT";   // string
let ok = true;     // boolean
let arr = [1,2,3]; // object (array)

Operators

  • Arithmetic: + - * / % **
  • Assignment: = += -= *=
  • Comparison: == (loose), === (strict), !=, <, >
  • Logical: &&, ||, !
let x = 7 % 2;       // 1
let eq = (5 === "5"); // false (strict)

Control structures

Decision: if / else if / else, switch.

if (n > 0) console.log("positive");
else console.log("non-positive");

Loops: for, while, do...while, for...of.

for (let i = 1; i <= 3; i++) console.log(i); // 1 2 3

These let a program take decisions and repeat blocks of code.

javascript-basics
6short5 marks

What is the Document Object Model (DOM)? Explain how JavaScript is used to manipulate the DOM.

Document Object Model (DOM) and JavaScript Manipulation

What is the DOM?

The Document Object Model is a platform- and language-neutral programming interface that represents an HTML/XML document as a tree of objects (nodes). The document object is the root; each element, attribute and piece of text is a node. The DOM lets scripts read and change the content, structure and style of a page dynamically.

document
  └─ html
       ├─ head ── title
       └─ body ── h1, p, div ...

Manipulating the DOM with JavaScript

1. Selecting elements

document.getElementById("demo");
document.getElementsByClassName("box");
document.querySelector("p.note");

2. Changing content / attributes / style

document.getElementById("demo").innerHTML = "Hello DOM";
img.setAttribute("src", "pic.png");
document.getElementById("demo").style.color = "red";

3. Creating / adding / removing nodes

let li = document.createElement("li");
li.textContent = "New item";
document.getElementById("list").appendChild(li);

4. Handling events

document.getElementById("btn").addEventListener("click", function() {
  alert("Clicked!");
});

Through these methods JavaScript makes web pages interactive and dynamic.

dom
7short5 marks

What is XSLT? Explain how XSLT is used to transform an XML document with an example.

XSLT (eXtensible Stylesheet Language Transformations)

XSLT is a language used to transform XML documents into other formats such as HTML, plain text, or another XML structure. It is part of the XSL family and uses XPath to navigate and select parts of the source XML. An XSLT processor reads the XML and the XSLT stylesheet and produces the output document.

How it works

  1. The XML file links to (or is paired with) an .xsl stylesheet.
  2. The stylesheet contains templates (<xsl:template match="...">) that match nodes.
  3. The processor walks the XML tree, applies matching templates, and emits the result tree.

Example

student.xml

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="student.xsl"?>
<students>
  <student><name>Ram</name><age>20</age></student>
  <student><name>Sita</name><age>21</age></student>
</students>

student.xsl

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html><body>
    <h2>Student List</h2>
    <table border="1">
      <tr><th>Name</th><th>Age</th></tr>
      <xsl:for-each select="students/student">
        <tr>
          <td><xsl:value-of select="name"/></td>
          <td><xsl:value-of select="age"/></td>
        </tr>
      </xsl:for-each>
    </table>
  </body></html>
</xsl:template>
</xsl:stylesheet>

This transforms the XML data into an HTML table for display in a browser.

xslt
8short5 marks

Explain arrays in PHP. Differentiate between indexed, associative and multidimensional arrays with examples.

Arrays in PHP

A PHP array is an ordered map that stores multiple values in a single variable, each value reachable by a key. PHP has three kinds of arrays.

1. Indexed array

Keys are automatic integers starting at 0.

$fruits = array("Apple", "Mango", "Banana");
echo $fruits[1];   // Mango

2. Associative array

Uses named (string) keys mapped to values — good for key→value data.

$marks = array("Ram" => 80, "Sita" => 90);
echo $marks["Sita"];  // 90

3. Multidimensional array

An array whose elements are themselves arrays (a table / matrix).

$students = array(
  array("Ram", 20),
  array("Sita", 21)
);
echo $students[1][0];  // Sita

Difference

TypeKeyUse
Indexednumeric (0,1,2…)simple lists
Associativestring nameskey–value pairs
Multidimensionalarrays inside arraystables / records

Arrays are traversed with foreach, e.g. foreach($marks as $name => $m) {...}.

php-arrays
9short5 marks

Explain user-defined functions in PHP with examples of passing arguments by value and by reference.

User-Defined Functions in PHP

A user-defined function is a reusable block of code created by the programmer using the function keyword. It is defined once and called whenever needed, optionally taking arguments and returning a value.

function greet($name) {
    return "Hello, $name";
}
echo greet("Ram");   // Hello, Ram

Passing arguments by value (default)

A copy of the value is passed; changes inside the function do not affect the original variable.

function addTen($x) {
    $x = $x + 10;
    return $x;
}
$a = 5;
addTen($a);
echo $a;   // 5  (original unchanged)

Passing arguments by reference

Prefix the parameter with &. The function works on the original variable, so changes persist outside.

function addTen(&$x) {
    $x = $x + 10;
}
$a = 5;
addTen($a);
echo $a;   // 15  (original modified)

Key difference

By valueBy reference
Passeda copythe actual variable (&)
Effectoriginal unchangedoriginal changed

Functions reduce repetition, improve readability and make code modular.

php-functions
10short5 marks

Explain the structure of a URL and the role of DNS in resolving domain names.

Structure of a URL and the Role of DNS

Structure of a URL

A URL (Uniform Resource Locator) is the address of a resource on the web. Example:

https://www.example.com:443/path/page.html?id=10#top
PartExampleMeaning
Scheme / protocolhttps://How to access (http, https, ftp)
Host / domainwww.example.comServer that holds the resource
Port:443Network port (default 80 http, 443 https)
Path/path/page.htmlLocation of the file on the server
Query string?id=10Parameters sent to the server
Fragment#topA section within the page

Role of DNS

Computers communicate using IP addresses, but domain names like www.example.com are easier for humans. The Domain Name System (DNS) is a distributed hierarchical database that translates (resolves) a domain name into its IP address.

Resolution steps:

  1. Browser checks its cache, then asks the resolver (ISP DNS server).
  2. The resolver queries the root server → TLD server (.com) → authoritative name server for example.com.
  3. The authoritative server returns the IP (e.g. 93.184.216.34).
  4. The browser then connects to that IP to fetch the page.

Thus DNS acts like the "phonebook of the Internet," mapping readable names to numeric addresses.

url-dns
11short5 marks

Differentiate between the GET and POST methods of submitting form data.

GET vs POST Methods

Both GET and POST are HTTP methods used to submit form data to the server, set via the form's method attribute, but they differ in how data is carried.

FeatureGETPOST
Data locationAppended to the URL as a query string (?name=ram)Sent in the HTTP request body
VisibilityVisible in the address barNot shown in the URL
Data sizeLimited (URL length limit, ~2KB)Large amounts allowed
Bookmark / cacheCan be bookmarked and cachedCannot
SecurityLess secure (data exposed)More secure (hidden from URL)
IdempotentYes — should only retrieve dataNo — used to change/create data
PHP access$_GET$_POST
Typical useSearch, navigation, filtersLogin, registration, file upload, sensitive data

Summary: Use GET to fetch data when it is safe to expose in the URL; use POST to send large or sensitive data such as passwords.

get-post
12short5 marks

What is AJAX? Explain how AJAX enables asynchronous communication between the client and the server.

AJAX (Asynchronous JavaScript And XML)

AJAX is a web technique that lets a web page exchange data with the server in the background and update parts of the page without reloading the whole page. It combines JavaScript, the XMLHttpRequest (or fetch) object, and a data format such as JSON or XML.

How AJAX enables asynchronous communication

  1. A user action (click, keypress) triggers a JavaScript function.
  2. JavaScript creates an XMLHttpRequest object and sends a request to the server.
  3. Because the request is asynchronous, the browser keeps responding to the user while waiting.
  4. The server processes the request and sends back only the needed data.
  5. A callback (the onreadystatechange/onload handler) fires when the response arrives, and JavaScript updates just the relevant part of the DOM.

Example

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
  if (xhr.readyState == 4 && xhr.status == 200) {
    document.getElementById("result").innerHTML = xhr.responseText;
  }
};
xhr.open("GET", "data.php?id=5", true);  // true = asynchronous
xhr.send();

Benefits

  • Faster, smoother user experience (partial page updates).
  • Less bandwidth — only data, not the full page, is transferred.
  • Used in live search, autocomplete, chat, and dynamic content loading.
ajax

Frequently asked questions

Where can I find the BSc CSIT (TU) Web Technology (BSc CSIT, CSC318) question paper 2075?
The full BSc CSIT (TU) Web Technology (BSc CSIT, CSC318) 2075 (regular) question paper is available free on Kekkei. You can read every question online and attempt the paper under timed exam conditions.
Does the Web Technology (BSc CSIT, CSC318) 2075 paper come with solutions?
Yes. Every question on this Web Technology (BSc CSIT, CSC318) past paper includes a step-by-step solution, plus instant AI feedback when you attempt it on Kekkei.
How many marks is the BSc CSIT (TU) Web Technology (BSc CSIT, CSC318) 2075 paper?
The BSc CSIT (TU) Web Technology (BSc CSIT, CSC318) 2075 paper carries 60 full marks and is meant to be completed in 180 minutes, across 12 questions.
Is practising this Web Technology (BSc CSIT, CSC318) past paper free?
Yes — reading and attempting this Web Technology (BSc CSIT, CSC318) past paper on Kekkei is completely free.