Web Tech Lab Code
Web Tech Lab Code
<html>
<head>
<title>BIODATA</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: white;
margin: 0;
padding: 20px;
}
.container {
max-width: 800px;
margin: 0 auto;
}
.heading {
text-align: center;
color: #333;
font-size: 32px;
margin-bottom: 20px;
}
.profile-img {
text-align: center;
margin-bottom: 20px;
}
.profile-img img {
border-radius: 50%;
width: 200px;
height: 200px;
border: 5px solid #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
padding: 10px;
border-bottom: 1px solid #ddd;
text-align: left;
}
th {
background-color: #f2f2f2;
}
.personal-info {
background-color: #f9f9f9;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
margin-bottom: 20px;
}
.section-heading {
font-size: 24px;
margin-bottom: 10px;
color: #333;
}
</style>
</head>
<body>
<div class="container">
<div class="heading">Biodata</div>
<div class="profile-img">
<img src="d:\HTML\Oki.jpg" alt="Profile Picture">
</div>
<div class="personal-info">
<div class="section-heading">Personal Information</div>
<table>
<tr>
<td>Name:</td>
<td>Sagar Bhattarai</td>
</tr>
<tr>
<td>Father's name:</td>
<td>Tikaram Bhattarai</td>
</tr>
<tr>
<td>Mother's name:</td>
<td>Sarmila Bhusal Bhattarai</td>
</tr>
<tr>
<td>DOB:</td>
<td>November 28, 2001</td>
</tr>
<tr>
<td>Address:</td>
<td>Kawasoti-02, Nawalpur, Nepal</td>
</tr>
<tr>
<td>Mobile no:</td>
<td>9811488333</td>
</tr>
<tr>
<td>Religion:</td>
<td>Hindu</td>
</tr>
<tr>
<td>Nationality:</td>
<td>Nepal</td>
</tr>
<tr>
<td>Gender:</td>
<td>Male</td>
</tr>
<tr>
<td>Qualification:</td>
<td>SLC</td>
</tr>
<tr>
<td>Hobby:</td>
<td>Watching Horror Movies, Playing Games</td>
</tr>
</table>
</div>
</div>
</body>
</html>
2.Create a Online submission form.
<html>
<head>
<style>
fieldset {
padding: 20px;
border-radius: 10px;
</style>
</head>
<body>
<fieldset>
<form>
Female <br><br>
Program:<select>
</form>
</fieldset>
</body>
</html>
3.
<xs:element name="TU">
<xs:complexType>
<xs:sequence>
<xs:element name="Employee">
<xs:complexType>
<xs:sequence>
<xs:element name="Post">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="5"/>
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Salary">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="15000"/>
<xs:maxInclusive value="25000"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Gender">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="male"/>
<xs:enumeration value="female"/>
<xs:enumeration value="other"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Username">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Password">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="8"/>
<xs:pattern value="[A-Za-z].*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
6. Create a XSLT to display the data from the XML document created in Qn 3,
with suitable format.
CREATE SESSION
<?php
session_start();
$_SESSION["username"]="Sagar bhattarai";
$_SESSION["password"]="wauuu";
echo "Session Created";
?>
DISPLAY SESSION
<?php
session_start();
//get display data from session variable
$username=$_SESSION["username"];
$password=$_SESSION["password"];
echo "Username: ".$username;
echo "<br> Password: ".$password;
?>
DESTROY SESSION
<?php
session_start();
//destroy session variable
unset($_SESSION["username"]);
unset($_SESSION["password"]);
echo "<br> Session Destroyed";
?>
For COOKIES
Create COOKIES
<?php
// Set cookies
setcookie("username", "Sagar bhattarai", time() + 3600); // Expires in 1 hour
setcookie("password", "wauuu", time() + 3600); // Expires in 1 hour
echo "Cookies have been set.";
?>
To Display Cookies
<?php
if (isset($_COOKIE["username"]) && isset($_COOKIE["password"])) {
echo "Username: " . htmlspecialchars($_COOKIE["username"]) . "<br>";
echo "Password: " . htmlspecialchars($_COOKIE["password"]);
} else {
echo "No cookies found.";
}
?>
<?php
$file = 'sagar.txt';
if (file_exists($file)) {
$content = file_get_contents($file);
echo "Content of sagar.txt: <br>";
echo $content;
} else {
echo "The file sagar.txt does not exist.";
}
?>
9. Write server-side code to create a database 'dbstudent' and a table
'tblstudent' with the fields ID, Name, Address and Phone No.
CREATE DATABASE
<?php
$con=mysqli_connect("localhost","root","");
$qry="create database dbstudent";
$result=mysqli_query($con,$qry);
if($result)
echo"database created successfully";
else
echo"Error creating database";
mysqli_close($con);
?>
CREATE TABLE
<?php
$con=mysqli_connect("localhost","root","","dbstudent");
$qry="CREATE TABLE tblstudent (
ID INT PRIMARY KEY NOT NULL,
Name VARCHAR(50) NOT NULL, Address VARCHAR(100), PhoneNo INT)";
$result=mysqli_query($con,$qry);
if($result)
echo"Table Created successfully";
else
"Error creating table";
mysqli_close($con);
?>
10. Write server-side program to perform insert, update, delete and display data
in the table created in Qn 9.
TO INSERT DATA
<?php
if(isset($_POST["btnSubmit"]))
{
$ID=$_POST["ID"];
$Name=$_POST["Name"];
$Address=$_POST["Address"];
$PhoneNo=$_POST["PhoneNo"];
$con=mysqli_connect("localhost","root","","dbstudent");
$qry = "INSERT INTO tblstudent (ID, Name, Address, PhoneNo) VALUES ('$ID', '$Name',
'$Address', '$PhoneNo')";
$result=mysqli_query($con,$qry);
if($result)
echo"Data Inserted Successfully";
else
echo"Error Inserting Data";
mysqli_close($con);
}
?>
<html>
<body>
<form method="POST">
ID:<input type="text" name="ID"> <br><br>
Name:<input type="text" name="Name"> <br><br>
Address:<input type="text" name="Address"> <br><br>
Phone No:<input type="text" name="PhoneNo"> <br><br>
<input type="Submit" name="btnSubmit" value="Insert Data">
</form>
</body>
</html>
To UPDATE DATA
<?php
if(isset($_POST["btnSubmit"]))
{
$ID=$_POST["ID"];
$Name=$_POST["Name"];
$Address=$_POST["Address"];
$PhoneNo=$_POST["PhoneNo"];
$con=mysqli_connect("localhost","root","","dbstudent");
TO DELETE DATA
<?php
if(isset($_POST["btnSubmit"]))
{
$ID=$_POST["ID"];
$con=mysqli_connect("localhost","root","","dbstudent");
$qry = "delete from tblstudent where ID='$ID'";
$result=mysqli_query($con,$qry);
if($result)
echo"Data Deleted Successfully";
else
echo"Error Deleting Data";
mysqli_close($con);
}
?>
<html>
<body>
<h2> Are you Sure want to Delete this Data? </h2>
<form method="POST">
ID:<input type="text" name="ID" required> <br><br>
TO DISPLAY DATA
<html>
<body>
<?php
$con=mysqli_connect("localhost","root","","dbstudent");
$qry="select ID, Name, Address, PhoneNo from tblstudent";
$result=mysqli_query($con, $qry);
$num=mysqli_num_rows($result);
if($num<0)
die("There is nothing to display");
?>
<table border="1" cellpadding="10" cellspacing="0">
<caption> Student List </caption>
<tr>
<th>ID</th>
<th>Name</th>
<th>Address</th>
<th>PhoneNo</th>
</tr>
<?php
while($row=mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td>".$row["ID"]."</td>";
echo "<td>".$row["Name"]."</td>";
echo "<td>".$row["Address"]."</td>";
echo "<td>".$row["PhoneNo"]."</td>";
echo "</tr>";
}
mysqli_close($con);
?>
</table>
</body>
</html>