Web Tech 2 Practical
Web Tech 2 Practical
Email)
Student.dtd
<!ELEMENT students (student+)>
<!ELEMENT student (name, roll_no, email)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT roll_no (#PCDATA)>
<!ELEMENT email (#PCDATA)>
Student.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE students SYSTEM "student.dtd">
<students>
<student>
<name>Mohammed Akib</name>
<roll_no>KCFYCS67</roll_no>
<email>[email protected]</email>
</student>
<student>
<name>Mohammed Amaan</name>
<roll_no>KCFYCS64</roll_no>
<email>[email protected]</email>
</student>
</students>
Validate.php
<?php
echo "Mohammed Akib<br>KCFYCS67<br>";
$xF = 'student.xml';
$dom = new DOMDocument();
$dom->load($xF);
if ($dom->validate()) {
echo "The XML file is valid according to the DTD.";
} else {
echo "The XML file is NOT valid according to the DTD.";
}
?>
Output
Hello.php code
<?php
if (isset($_REQUEST['action'])) {
$action = $_REQUEST['action'];
if ($action == 'mouseover') {
echo "Mouse over event detected!";
} elseif ($action == 'button_click') {
echo "Button click event detected!";
}}
?>
6) Create a webpage that allows users to hide, show, fade in, fade out, and
toggle the visibility of a <div> element containing text
Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Visibility Demo</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<style>
#demo {
width: 200px;
padding: 20px;
border: 1px solid #646765;
background-color: #E9967A; }
</style>
<body>
<h4>Mohammed Akib KCFYCS67<br></h4>
<button id="hideBtn">Hide</button>
<button id="showBtn">Show</button>
<button id="fadeOutBtn">Fade Out</button>
<button id="fadeInBtn">Fade In</button>
<button id="toggleBtn">Toggle</button>
<div id="demo">
<h2>This is a animation box!</h2>
<p>This is some text inside the paragraph. You can hide, show, fade in, fade out, and toggle the
visibility of this content!</p>
</div>
<script>
$(document).ready(function(){
// Hide the entire div when the Hide button is clicked
$("#hideBtn").click(function(){
$("#demo").hide();
});
$("#showBtn").click(function(){
$("#demo").show();
});
$("#fadeOutBtn").click(function(){
$("#demo").fadeOut();
});
$("#fadeInBtn").click(function(){
$("#demo").fadeIn();
});
$("#toggleBtn").click(function(){
$("#demo").toggle();
});
});
</script>
</body>
</html>
Output
7) Create a webpage with a <div> element and buttons to slide down,
slide up, and animate its size while fading in and out.
Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Slide and Animate Demo</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<h4>Mohammed Akib KCFYCS67 <br></h4>
<button id="slideDownBtn">Slide Down</button>
<button id="slideUpBtn">Slide Up</button>
<button id="fadeOutBtn">Fade Out</button>
<button id="fadeInBtn">Fade In</button>
<button id="animateSizeBtn">Animate Size</button>
// Fade out the demo box when the Fade Out button is clicked
$("#fadeOutBtn").click(function(){
$("#demoBox").fadeOut();
});
// Animate the size of the demo box when the Animate Size button is clicked
$("#animateSizeBtn").click(function(){
$("#demoBox").animate({
width: "500px",
height: "200px"
}, 1000); // Animate size over 1 second
});
});
</script>
</body>
</html>
Output
1. Calculating factorial
<?php
function factorial($n) {
$result = 1;
for ($i = 1; $i <= $n; $i++) {
$result *= $i;
}
return $result;}
echo "Mohammed Akib KCFYCS67<br>";
echo "Factorial of 20: " . factorial(5) . "<br>";
?>
Output
4. Evaluating Expressions
Code
<?php
function evaluateExpression($expression) {
eval("\$result = $expression;");
return $result;
}
$expression = "3 + 10 * 6";
echo "Mohammed Akib KCFYCS67<br>";
echo "The result of '$expression' is: " . evaluateExpression($expression);
?>
Output
9) Write PHP scripts for (using MySQLi and PHP Data Objects (PDO))-
Working with Databases (Storing Records / Reprieving Records and Display
them)
a. Storing and Retrieving Cookies
b. Storing and Retrieving Sessions
MySQLi
STORING RECORDS:-
<?php
$servername="localhost";
$username="root";
$password="";
$database="KCFYCS73";
$con=mysqli_connect($servername,$username,$password,$database);
$sql="INSERT INTO Students(firstname,lastname,email)
VALUES('Ananya','Thakur','[email protected]')";
if(mysqli_query($con,$sql)){
echo "New Record added successfully";
}else{
echo "Error".mysqli_error($con);
}
mysqli_close($con);
?>
OUTPUT:-
b. Storing Sessions
CODE:-
<?php
echo"Anushka Thakur<br>KCFYCS73<br>";
session_start();
$_SESSION["username"]="Anushka";
echo"Session is set!";
?>
OUTPUT:-
Retrieve a Session
CODE:-
<?php
echo"Anushka Thakur<br>KCFYCS73<br>";
session_start();
if(isset($_SESSION["username"])){
echo"Welcome, ".$_SESSION["username"];
}else{echo"No session found!";}
?>
OUTPUT:-