0% found this document useful (0 votes)
4 views

Web Tech Lab Code

The document contains various tasks related to web development, including creating a biodata webpage, an online submission form, XML and its validation using DTD and XSD, XSLT for displaying XML data, and PHP scripts for session management, cookie handling, file reading, database creation, and CRUD operations. Each task includes relevant code snippets demonstrating the implementation of the specified functionality. The document serves as a comprehensive guide for practical web programming exercises.

Uploaded by

admin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Web Tech Lab Code

The document contains various tasks related to web development, including creating a biodata webpage, an online submission form, XML and its validation using DTD and XSD, XSLT for displaying XML data, and PHP scripts for session management, cookie handling, file reading, database creation, and CRUD operations. Each task includes relevant code snippets demonstrating the implementation of the specified functionality. The document serves as a comprehensive guide for practical web programming exercises.

Uploaded by

admin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

1: Create a webpage describing your bio-data.

(The page should be attractive


with a table, figure, etc.)

<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>

<title> Here we go </title>

<style>

fieldset {

width: 300px; /* Adjust width as needed */

padding: 20px;

border: 2px solid #ccc;

border-radius: 10px;

margin: auto; /* Center the fieldset */

</style>

</head>

<body>

<fieldset>

<form>

ID: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; <input type="Number"


placeholder=""> <br><br>

Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" placeholder=""><br><br>

Password:&nbsp;<input type="password" placeholder=" "><br><br>

Gender:<input type="radio" name="wauuu" >

Male<input type="radio" name="wauuu">

Female <br><br>

Program:<select>

<option> BCA </option>

<option > BBA </option>

<option> BCs csit </option>

</select> <br> <br>


Description:<textarea rows="5" cols="20"> </textarea> <br> <br>

<input type="Submit" value="submit">

<input type="Reset" value="Clear all">

</form>

</fieldset>

</body>

</html>
3.

<?xml version="1.0" encoding="UTF-8"?>


<TU>
<Employee>
<Post>Accountant</Post>
<Salary>25000</Salary>
<Gender>Female</Gender>
<Username>salina_pkh</Username>
<Password>OkiCool123</Password>
</Employee>
</TU>
4. Use DTD for validating the XML document created in Qn 3.
<!DOCTYPE TU [
<!ELEMENT TU (Employee)>
<!ELEMENT Employee (Post, Salary, Gender, Username, Password)>
<!ELEMENT Post (#PCDATA)>
<!ELEMENT Salary (#PCDATA)>
<!ELEMENT Gender (#PCDATA)>
<!ELEMENT Username (#PCDATA)>
<!ELEMENT Password (#PCDATA)>
]>
5. Use XSD to validate the XML created in QN 3 and follows the as below:
XSD Restrictions:
i.The Username must have at least 8 characters.
ii.The character limit for post is 5 to 8.
iii.The password must be at least 8 characters long and should
start with only Aa-Zz.
iv.The gender must be one of male, female or other.
v.The salary should range from Rs. 15,000 to Rs. 25,000.

<?xml version="1.0" encoding="UTF-8"?>


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<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.

<?xml version="1.0" encoding="UTF-8"?>


<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>

<!-- Root template -->


<xsl:template match="/">
<html>
<head>
<title>Employee Details</title>
<style>
table {
width: 50%;
border-collapse: collapse;
margin: 25px 0;
font-size: 18px;
text-align: left;
}
th, td {
padding: 12px;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f2f2f2; }
</style> </head> <body>
<h2>Employee Details</h2>
<table>
<tr>
<th>Post</th>
<th>Salary</th>
<th>Gender</th>
<th>Username</th>
<th>Password</th>
</tr>
<xsl:for-each select="TU/Employee">
<tr>
<td><xsl:value-of select="Post"/></td>
<td><xsl:value-of select="Salary"/></td>
<td><xsl:value-of select="Gender"/></td>
<td><xsl:value-of select="Username"/></td>
<td><xsl:value-of select="Password"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
7. Write a server-side program to demonstrate creating and destroying session
and cookies.
For SESSION

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.";
}
?>

COOKIES are automatically after the timing will over.


8. Create a text file to store a line of text and read to display using a server-side
programming language.

<?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");

$qry = "update tblstudent set Name='$Name', Address='$Address', PhoneNo='$PhoneNo'


where ID='$ID'";
$result=mysqli_query($con,$qry);
if($result)
echo"Data Updated Successfully";
else
echo"Error Updating 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="Update Data">
</form>
</body>
</html>

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>

<input type="Submit" name="btnSubmit" value="Delete Data">


</form>
</body>
</html>

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>

You might also like