WT Slip Solutions
WT Slip Solutions
WT Slip Solutions
Slip 1
Write a PHP script to keep track of number of times the web page has been accessed (Use Session
Tracking).
//program to keep track of no of times the web page is visited using SESSION
<?php
session_start();
if(isset($_SESSION[‘c’]))
$_SESSION[‘c’]+=1;
else
$_SESSION[‘c’]=1;
?>
Slip 2
Write a PHP script to change the preferences of your web page like font style, font size, font color,
background color using cookie. Display selected setting on next web page and actual implementation
(with new settings) on third page (Use Cookies).
Ass1_a2_21.php
<?php
$fn=$_REQUEST[‘fn’];
$fs=$_REQUEST[‘fs’];
$s=$_REQUEST[‘s’];
$bg=$_REQUEST[‘bg’];
$fc=$_REQUEST[‘fc’];
setcookie(‘fn’,$fn);
setcookie(‘fs’,$fs);
setcookie(‘s’,$s);
setcookie(‘bg’,$bg);
setcookie(‘fc’,$fc);
echo “$fn<br>”;
echo “$fs<br>”;
echo “$s<br>”;
echo “$bg<br>”;
echo “$fc<br>”;
?>
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8”>
<title>Document</title>
</head>
<body>
<form action=”ass1_a2_2.php”>
<br>
</form>
</body>
</html>
ass1_a2_2.php
<?php
$fn=$_COOKIE[‘fn’];
$fs=$_COOKIE[‘fs’];
$s=$_COOKIE[‘s’];
$bg=$_COOKIE[‘bg’];
$fc=$_COOKIE[‘fc’];
$txt=$_REQUEST[‘ta’];
echo”<body bgcolor=$bg>”;
echo”</body>”;
?>
ass1_a2.html
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Document</title>
</head>
<body>
<form action=”ass1_a2_1.php”>
<b>Font name</b><br>
<select name=”fn”>
<option value=”Jokerman”>Jokerman</option>
</select><br><br>
<b>Font Style</b><br>
<select name=”fs”>
<option value=”Regular”>Regular</option>
<option value=”Oblique”>Oblique</option>
<option value=”Bold”>Bold</option>
</select><br><br>
<b>Size</b><br>
<select name=”s”><br>
<option value=”3”>small</option>
<option value=”5”>medium</option>
<option value=”7”>large</option>
</select><br><br>
<b>Background color</b>
<select name=”bg”><br>
<option value=”red”>red</option>
<option value=”green”>green</option>
<option value=”blue”>blue</option>
</select><br><br>
<b>Font Color</b>
<select name=”fc”><br>
<option value=”red”>red</option>
<option value=”green”>green</option>
<option value=”blue”>blue</option>
</select><br><br>
</form>
</body>
</html>
Slip 3
Write a PHP script to accept username and password. If in the first three chances, username and
password entered is correct then display second form with “Welcome message” otherwise display
error message. [Use Session]
ass1_b1.html
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8”>
<title>Document</title>
</head>
<body>
<form action=”ass1_b1.php”>
</form>
</body>
</html>
ass1_b1.php
<?php
session_start();
$u=$_REQUEST[‘uname’];
$p=$_REQUEST[‘password’];
if(isset($_SESSION[‘c’]))
echo “Welcome”;
else if($_SESSION[‘attempt’]<=3)
$_SESSION[‘attempt’]+=1;
else
else
$_SESSION[‘c’]=1;
$_SESSION[‘attempt’]=1;
{
echo “valid”;
?>
Slip 4
Write a PHP script to accept Employee details (Eno, Ename, Address) on first page. On second page
accept earning (Basic, DA, HRA). On third page print Employee information (Eno, Ename, Address,
Basic, DA, HRA, Total) [ Use Session].
Empinfo.html
<!DOCTYPE html>
<html >
<head>
<title>Document</title>
</head>
<body>
<form action=”empinfo.php”>
</form>
</body> </html>
empinfo.php
<?php
session_start();
$_SESSION[‘eno’]=$_GET[‘eno’];
$_SESSION[‘ename’]=$_GET[‘ename’];
$_SESSION[‘addr’]=$_GET[‘addr’];
?>
<form action=”showempinfo.php”>
Basic:<br><input type=”text”name=”basic”><br>
DA:<br><input type=”text”name=”da”><br>
HRA:<br><input type=”text”name=”hra”><br>
</form>
showempinfo.php
<?php
session_start();
$basic=$_GET[‘basic’];
$da=$_GET[‘da’];
$hra=$_GET[‘hra’];
$eno=$_SESSION[‘eno’];
$ename=$_SESSION[‘ename’];
$addr=$_SESSION[‘addr’];
$total=$basic+$da+$hra;
echo”<br>Employee details:”;
echo”<br>Basic: $basic”;
echo”<br>DA: $da”;
echo”<br>HRA: $hra”;
echo”<br>Total salary=$total”;
?>
<table border=”1”>
<tr><td>Basic</td><td><?php echo”$basic”?></td></tr>
<tr><td>DA</td><td><?php echo”$da”?></td></tr>
<tr><td>HRA</td><td><?php echo”$hra”?></td></tr>
</table>
Slip 5
Create XML file named “Item.xml”with item-name, item-rate, item quantity Store the details of 5
Items of different Types
Item.xml
<items>
<item>
<itemname>Pencil</itemname>
<itemrate>10</itemrate>
<quantity>3</quantity>
</item>
<item>
<itemname>Pen</itemname>
<itemrate>20</itemrate>
<quantity>3</quantity>
</item>
<item>
<itemname>Eraser</itemname>
<itemrate>5</itemrate>
<quantity>5</quantity>
</item>
<item>
<itemname>Sharpner</itemname>
<itemrate>8</itemrate>
<quantity>5</quantity>
</item>
<item>
<itemname>Compass</itemname>
<itemrate>20</itemrate>
<quantity>5</quantity>
</item>
</items>
Slip 6
Write PHP script to read “book.xml” file into simpleXML object. Display attributes and elements .
( simple_xml_load_file() function )
Book.xml
<bookstore>
<books category=”technical”>
<book_no>1</book_no>
<book_name>def</book_name>
<author_name>xxx</author_name>
<price>100</price>
<year>1990</year>
</books>
<books category=”Cooking”>
<book_no>2</book_no>
<book_name>ccc</book_name>
<author_name>aaa</author_name>
<price>200</price>
<year>1950</year>
</books>
<books category=”YOGA”>
<book_no>3
<book_name>ddd</book_name>
<author_name>zzz</author_name>
<price>150</price>
<year>2016<year>
</books>
</bookstore>
Book.php
<?php
var_dump($xml);
?>
Slip 7
Write a PHP script to read “Movie.xml” file and print all MovieTitle and ActorName of file using
DOMDocument Parser. “Movie.xml” file should contain following information with at least 5 records
with values. MovieInfoMovieNo, MovieTitle, ActorName ,ReleaseYear
<?php
$doc->load('Movie.xml');
$movies = $doc->getElementsByTagName('MovieInfo');
$titles = $movie->getElementsByTagName('MovieTitle');
$title = $titles->item(0)->nodeValue;
$actors = $movie->getElementsByTagName('ActorName');
$actor = $actors->item(0)->nodeValue;
?>
Slip 8
Write a JavaScript to display message ‘Exams are near, have you started preparing for? (use alert box )
and Accept any two numbers from user and display addition of two number .(Use Prompt and confirm
box)
Add.html
<!DOCTYPE html>
<html>
<head>
<title>Document</title>
</head>
<body>
<script>
</script>
</body>
</html>
Slip 9
Write a JavaScript function to validate username and password for a membership form
Validate.html
<!DOCTYPE html>
<html >
<head>
<title>Document</title>
</head>
<body>
<script>
return false;
}
else {
return true;
}
}
if (validateForm(username, password)) {
}
</script>
</body>
</html>
Slip 10
Create a HTML file to insert text before and after a Paragraph using jQuery. [Hint : Use before( ) and
after( )]
Beforeafter.html
<html>
<head>
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js”></script>
<script>
$(document).ready(function(){
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
</body>
</html>
Slip 11
Write a Javascript program to accept name of student, change font color to red, font size to 18 if student
name is present otherwise on clicking on empty text box display image which changes its size (Use
onblur, onload, onmousehover, onmouseclick, onmouseup)
<html>
<head>
<title>Student Name</title>
<script>
function changeStyle(element) {
if (element.value == “”) {
element.style.color = “”;
element.style.fontSize = “”;
document.getElementById(“image”).style.display = “block”;
document.getElementById(“image”).style.width = “100px”;
document.getElementById(“image”).style.height = “100px”;
} else {
element.style.color = “red”;
element.style.fontSize = “18px”;
document.getElementById(“image”).style.display = “none”;
}
}
</script>
</head>
<body>
</body>
</html>
Slip 12
Write AJAX program to read contact.dat file and print the contents of the file in a tabular format when
the user clicks on print button. Contact.dat file should contain srno, name, residence number, mobile
number, Address. [Enter at least 3 record in contact.dat file]
contact.dat file:
1,John,1234567890,0987654321,123 Main St
3,Jack,1234567892,0987654323,789 Pine St
<html>
<head>
<script>
function readData() {
xhttp. {
document.getElementById("printTable").innerHTML = this.responseText;
}
};
xhttp.send();
</script>
</head>
<body>
<table id="printTable"></table>
</body>
</html>
Slip 13
Write AJAX program where the user is requested to write his or her name in a text box, and the server
keeps sending back responses while the user is typing. If the user name is not entered then the message
displayed will be, “Stranger, please tell me your name!”. If the name is Rohit, Virat, Dhoni, Ashwin or
Harbhajan , the server responds with “Hello, master !”. If the name is anything else, the message will be
“, I don’t know you!”
Demo.html
<html>
<head>
</head>
<body>
<script type="text/javascript">
function getName() {
if (name == "") {
else {
xhttp. {
document.getElementById("response").innerHTML = response;
};
xhttp.open("GET", "demo.php?name=" + name, true);
xhttp.send();
</script>
<form>
</form>
<div id="response"></div>
</body>
</html>
Demo.php
<?php
if (isset($_GET['name'])) {
$name = $_GET['name'];
} else {
}
}
?>
Slip 14
Create TEACHER table as follows TEACHER(tno, tname, qualification, salary). Write Ajax program to
select a teachers name and print the selected teachers details
<html>
<head>
<script>
function showTeacher(str) {
var xhttp;
if (str == "") {
document.getElementById("teacherDetails").innerHTML = "";
return;
xhttp. {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("teacherDetails").innerHTML = this.responseText;
};
xhttp.send();
</script>
</head>
<body>
<form>
<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");
$result = mysqli_query($con,$sql);
mysqli_close($con);
?>
</select>
</form>
<br>
<div id="teacherDetails"><b>Details will be listed here.</b></div>
</body>
</html>
//PHP Script
<?php
$name = $_REQUEST['name'];
$con = mysqli_connect("localhost","my_user","my_password","my_db");
$result = mysqli_query($con,$sql);
mysqli_close($con);
?>
Slip 15
Write Ajax program to fetch suggestions when is user is typing in a textbox. (eg like google
suggestions. Hint create array of suggestions and matching string will be displayed)
<html>
<head>
<script type="text/javascript">
function suggest()
for(i=0;i<arr.length;i++)
if(arr[i].substring(0,input.length).toLowerCase() == input.toLowerCase())
document.getElementById("txt2").innerHTML = suggest;
</script>
</head>
<body>
</body>
</html>
Slip 16
Write Ajax program to get book details from XML file when user select a book name. Create XML file for
storing details of book(title, author, year, price).
BookInfo.xml
<BookList>
<Book>
<Year>1925</Year>
<Price>$7.99</Price>
</Book>
<Book>
<Author>Harper Lee</Author>
<Year>1960</Year>
<Price>$8.99</Price>
</Book>
<Book>
<Author>J.D. Salinger</Author>
<Year>1951</Year>
<Price>$9.99</Price>
</Book>
</BookList>
Html file :
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<script>
function getBookDetails(bookName) {
xhttp. {
if (book[i].getElementsByTagName("Title")[0].childNodes[0].nodeValue == bookName) {
}
}
}
};
xhttp.send();
}
</script>
</body>
</html>
Slip 17
Write a Java Script Program to show Hello Good Morning message onload event using alert box and
display the Student registration from.
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Document</title>
</head>
<body>
<script>
window.>
}
</script>
</body>
</html>
Slip 18
Write a Java Script Program to print Fibonacci numbers on onclick event. Write a Java Script Program to
print Fibonacci numbers on onclick event.
<html>
<head>
<title>Fibonacci Series</title>
<script type=”text/javascript”>
function ibonacci(n)
var a = 0, b = 1, c;
document.write(“<h3>Fibonacci Series till “+n+”</h3>”);
{
c = a + b;
a = b;
b = c;
document.write(c+” “);
}
</script>
</head>
<body>
<form >
</form>
</body>
</html>
Slip 19
Write a Java Script Program to validate user name and password on onSubmit event.
Validate.html
<html>
<head>
<script>
function validate(){
if (username == “”){
return false;
if (password == “”){
return false;
}
return true;
</script>
</head>
<body>
<form validate()”>
<br>
<br>
</form>
Slip 20
student.xml
<Students>
<Student>
<Name>John Doe</Name>
<Age>25</Age>
<Gender>Male</Gender>
<Major>Computer Science</Major>
<GPA>3.8</GPA>
</Student>
<Student>
<Name>Jane Doe</Name>
<Age>23</Age>
<Gender>Female</Gender>
<Major>English</Major>
<GPA>3.6</GPA>
</Student>
<Student>
<Name>Jacob Smith</Name>
<Age>22</Age>
<Gender>Male</Gender>
<Major>History</Major>
<GPA>3.2</GPA>
</Student>
<Student>
<Name>Jennifer Smith</Name>
<Age>24</Age>
<Gender>Female</Gender>
<Major>Biology</Major>
<GPA>3.9</GPA>
</Student>
Slip 21
Add a JavaScript File in Codeigniter. The Javascript code should check whether a number is positive or
negative.
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Document</title>
</head>
<body>
<script type=”text/javascript”>
function checkPositiveOrNegative(number){
} else {
}
}
</script>
<form >
</form>
</body>
</html>
Slip 22
<?php
$selected = mysql_select_db($dbname,$dbhandle)
//Create table
(
rollno INT NOT NULL,
)”;
if(! $retval )
{
}
Slip 23
Create a table student having attributes(rollno, name, class) containing atleast 5 recodes . Using
codeigniter, display all its records.
rollno INT,
name VARCHAR(30),
class VARCHAR(30)
);
INSERT INTO student VALUES
//Codeigniter
$this->db->select('*');
$this->db->from('student');
$query = $this->db->get();
$result = $query->result_array();
Slip 24
Write a PHP script to create student.xml file which contains student roll no, name, address, college and
course. Print students detail of specific course in tabular format after accepting course as input from
user
<?php
$course = $_POST['course'];
$xml->formatOutput = true;
$xml_student = $xml->createElement("student");
$xml_student = $xml->appendChild($xml_student);
$xml_rollno = $xml_student->appendChild($xml_rollno);
$xml_name = $xml_student->appendChild($xml_name);
$xml_address = $xml_student->appendChild($xml_address);
$xml_college = $xml_student->appendChild($xml_college);
$xml_course = $xml_student->appendChild($xml_course);
$xml->save("student.xml");
$xml = simplexml_load_file('student.xml');
echo "<table>";
echo "<tr>";
echo "<th>Name</th>";
echo "<th>Address</th>";
echo "<th>College</th>";
echo "<th>Course</th>";
echo "</tr>";
foreach($xml->children() as $student) {
if($student->course == $course) {
echo "<tr>";
echo "<td>".$student->rollno."</td>";
echo "<td>".$student->name."</td>";
echo "<td>".$student->address."</td>";
echo "<td>".$student->college."</td>";
echo "<td>".$student->course."</td>";
echo "</tr>";
echo "</table>";
?>
Slip 25
Write a script to create “cricket.xml” file with multiple elements as shown below:
<CricketTeam>
<Team country=”Australia”>
<player>____</player>
<runs>______</runs>
<wicket>____</wicket>
</Team>
</CricketTeam>
#!/bin/bash
#add elements
Slip 26
Create employee table as follows EMP (eno, ename, designation, salary). Write Ajax program to select
the employees name and print the selected employee’s details.
EmployeeDetails.html
<html>
<head>
function getEmployeeName()
{
{
}
};
req.send();
</script>
</head>
<body>
</body>
</html>
getEmployeeDetails.php
<?php
$ename = $_GET[‘ename’];
$servername = “localhost”;
$username = “username”;
$password = “password”;
$dbname = “myDB”;
// Create connection
// Check connection
if ($conn->connect_error) {
$sql = “SELECT eno, ename, designation, salary FROM EMP WHERE ename = ‘$ename’”;
$result = $conn->query($sql);
$row = $result->fetch_assoc();
echo json_encode($empDetails);
$conn->close();
?>
Slip 27
Create web Application that contains Voters details and check proper validation for (name, age, and
nationality), as Name should be in upper case letters only, Age should not be less than 18 yrs and
Nationality should be Indian.(use HTML-AJAX-PHP)
<html>
<head>
<title>Voter Registration</title>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
$(document).ready(function () {
$("#form_submit").click(function () {
}
else if (/[^A-Z]/g.test(form_name)) {
}
}
}
else {
$.ajax({
url: "voter_details.php",
method: "POST",
data: { form_name: form_name, form_age: form_age, form_nationality:
form_nationality },
alert(data);
}
})
}
});
});
</script>
</head>
<body>
<form>
</form>
</body>
</html>
<?php
$form_name = $_POST['form_name'];
$form_age = $_POST['form_age'];
$form_nationality = $_POST['form_nationality'];
if($result){
}
else{
}
}
?>
Slip 28
Write a PHP script using AJAX concept, to check user name and password are valid or Invalid (use
database to store user name and password).
<html>
<head>
<script>
function validateForm()
return false;
if (userName == "")
return false;
}
if (password == "")
return false;
let xhr;
if (window.XMLHttpRequest)
else if (window.ActiveXObject)
else
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr. () {
if(response == "invalid")
else
alert("Login successfully");
</script>
</head>
<body>
<br><br>
<br><br>
</form>
</body>
</html>
<?php
//checklogin.php
$userName = $_POST['user_name'];
$password = $_POST['password'];
//connect to database
$sql = "SELECT * FROM user_data WHERE user_name = '$userName' AND password = '$password'";
$result = $db->query($sql);
$row = $result->fetch_assoc();
if ($row)
echo json_encode("valid");
else
echo json_encode("invalid");
?>
Slip 29
Write a PHP script for the following: Design a form to accept a number from the user. Perform the
operations and show the results.
1) Fibonacci Series.
2) To find sum of the digits of that number.
Show.html
<html>
<head>
<title>Form for number input</title>
</head>
<body>
</form>
</body>
</html>
Show.php
<?php
if (isset($_POST['submit'])) {
$num = $_POST['num'];
$x = 0;
$y = 1;
$z = $x + $y;
$x = $y;
$y = $z;
}
echo "<br><br>";
$sum = 0;
while($num > 0) {
$num = (int)($num/10);
echo $sum;
?>
Slip 30
Create a XML file which gives details of books available in “Bookstore” from following categories.
1) Yoga
2) Story
3) Technical
Bookcategory.xml
<Bookstore>
<Yoga>
<Book>
<Book_Author>Rajkumar Yogi</Book_Author>
<Book_Price>$14.99</Book_Price>
</Book>
<Book>
<Book_Price>$15.99</Book_Price>
</Book>
</Yoga>
<Story>
<Book>
<Book_Author>Dr. Seuss</Book_Author>
<Book_Price>$7.99</Book_Price>
</Book>
<Book>
<Book_Author>Antoine de Saint-Exupéry</Book_Author>
<Book_Price>$10.99</Book_Price>
</Book>
</Story>
<Technical>
<Book>
<Book_Price>$20.99</Book_Price>
</Book>
<Book>
<Book_Author>Donald E. Knuth</Book_Author>
<Book_Price>$25.99</Book_Price>
</Book>
</Technical>
</Bookstore>