SR - No. Experiment Page No. Date Marks Signature From To
SR - No. Experiment Page No. Date Marks Signature From To
TITLE: Designing a webpage using an html that contains a time table and form for
Registration Page.
THEORY:
HTML – HyperText Markup Language is basically divided into two portions head and
body. Headis used to preserve information for browsers and search engines like title, meta
tags etc. While the body part contains the things that you want to display to the user in terms
of a web page.
<HTML>
<HEAD>
Title, meta tags information goes here
</HEAD>
<BODY>
Display portion code goes here
</BODY>
</HTML>
HTML TABLES:
● A table is defined using the <table> element, and contains a number of table cells ( <td>,
for
―table data columns ) which are organized into table rows ( <tr>). The markup
(HTML code) for a table is always based on rows, never columns.
● Table cells which act as column headers or row headers should use the <th> (table
header)element.
● Table cells can be merged using the colspan and rowspan attributes.
CODE:
<html>
<head>
<title>HTML Table Background</title>
</head>
<body>
<table border="1" bordercolor="green" bgcolor="yellow">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr>
THEORY:
The <form> element is required to wrap around the form‘s content — without it
you don‘thave a web form. The <form> tag can have a few attributes.
The <input> element defines an area where you can type or paste information.
<input type="text"> to specify that we want single line text input fields (the type
attribute is mandatory). Other type attributes values are password, radio, checkbox,
Every <input> element must also have a name attribute that you, the developer, specify.
The only exceptions to this rule are special cases where the value attribute is set to the
same value asthe type attribute, e.g., type="submit" or type="reset". The name attribute
is needed for the database or other data destination to uniquely identify that piece of
data.
Every <input> element should also have a value attribute. The value of this attribute
depends on the element it is used on. The field in the value will be displayed as it is
inside the text box.
<input type="submit">
Special <input> element with the attribute value="submit". Instead of rendering a text
box for input, the submit input will render a button that, when clicked, submits the
form‘s data to whatever target the form has specified.
When the submit button will be clicked, It will directly go to the path given in the form
action. The data transfer will be as per the method (GET or POST) you mentioned.
CODE:
• PR-1-1.html
<!DOCTYPE html>
<head>
<title>PR-1</title>
<style>
body {
margin: 0;
padding: 0;
}
.container {
width: 80%;
height: auto;
margin: 25px auto;
padding: 2rem;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
background-color: #FEE2C5;
border-radius: 5px;
}
.title {
font-size: 1.5rem;
}
.form {
font-size: 1.2rem;
padding: 10px;
width: 65%;
}
.form input, .form textarea {
width: 100%;
margin: 15px 0;
}
.form select {
padding: 5px 10px;
margin-bottom: 15px;
background-color: #D7A86E;
border-radius: 4px;
}
.form button {
padding: 7px 15px;
background-color: #D7A86E;
border-radius: 4px;
}
</style>
</head>
<body>
<div class="container">
Output: -
• PR-1-2.html
<!DOCTYPE html>
<head>
<title>PR-1</title>
<style>
body {
margin: 0;
padding: 0;
}
.container {
width: 80%;
height: auto;
margin: 25px auto;
padding: 2rem;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
background-color: #FEE2C5;
border-radius: 5px;
}
.title {
font-size: 1.5rem;
}
.form {
font-size: 1.2rem;
padding: 10px;
width: 65%;
}
.form input, .form textarea {
width: 100%;
margin: 15px 0;
}
.form select {
Output: -
• PR-1-3.html
<!DOCTYPE html>
<head>
<title>PR-1</title>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td,
th {
border: 1px solid black;
text-align: center;
padding: 10px;
}
tr:nth-child(even) {
background-color: aqua;
}
tr:nth-child(odd) {
background-color: lawngreen;
}
</style>
</head>
<body>
<h3 style="background-color: rgb(183, 250, 117); text-align: center">
Jaitra Patel 200020107537(C.E) sem-6
</h3>
<h1 style="background-color: rgb(125, 250, 250); text-align: center">
Employee Data
</h1>
<table>
<tr>
<th>Employee Number</th>
<th>Employee Name</th>
<tr>
<td>8526475789</td>
<td>SMITH</td>
<td>20000</td>
<td>
<img
style="width: 100px; height: 120px"
src="https://encrypted-
tbn0.gstatic.com/images?q=tbn:ANd9GcRruWFn0SxoT8sV9s13_u1Ez3YaUq5cPAWTxTAZLnCwJHwDP
UCwMW6vNl2flNrUTAorsRU&usqp=CAU"
/>
</td>
<tr>
<td>9411259101</td>
<td>ALEX</td>
<td>30000</td>
<td><img style="width:100px;height:120px;"
src="https://encrypted-
tbn0.gstatic.com/images?q=tbn:ANd9GcRruWFn0SxoT8sV9s13_u1Ez3YaUq5cPAWTxTAZLnCwJHwDP
UCwMW6vNl2flNrUTAorsRU&usqp=CAU">
</td>
Output: -
QUIZ:
TITLE: Designing a web page with CSS containing A) Relative, Absolute positioning B)
Margin and Padding C) Pseudo class
THEORY:
STATIC POSITIONING:
.static { position:
static;
}
<div class="static"> Write something here </static>
static is the default value. An element with position: static; is not positioned in any
special way.A static element is said to be not positioned and an element with its position
set to anything elseis said to be positioned.
RELATIVE POSITIONING:
.relative1 { position:
relative;
}
.relative2 { position:
relative;
top: -
20px;left:
20px;
background-color: white;width: 500px;
}
<div class="relative1">
relative behaves the same as static unless you add some extra properties.
</div>
<div class="relative2"> </div>
Setting the top, right, bottom, and left properties of a relatively-positioned element will
cause it to be adjusted away from its normal position. Other content will not be adjusted
to fit into any gap left by the element.
A fixed element is positioned relative to the viewport, which means it always stays in
the same place even if the page is scrolled. As with relatives, the top, right, bottom, and
left properties are used.
.fixed { position:
fixed; bottom: 0;
right: 0; width:
200px;
background-color: white;
}
<div class="fixed">
</div>
ABSOLUTE POSITIONING:
absolute is the trickiest position value. absolute behaves like fixed except relative to the
nearest positioned ancestor instead of relative to the viewport. If an absolutely-
positioned element has no positioned ancestors, it uses the document body, and still
moves along with page scrolling. Remember, a "positioned" element is one whose
position is anything except static.
.relative { position:
relative; width:
600px; height:
400px;
}
.absolute { position:
absolute;
top: 120px;
right: 0;
width:
300px;
height: 200px;
}
<div class="relative">
This element is relatively-positioned. If this element was position: static; its absolutely-
positioned child would escape and would be positioned relative to the document body.
<div class="absolute">
This element is absolutely-positioned. It's positioned relative to its parent.
</div>
CSS margins are used to create space around the element. We can set the
different size ofmargins for individual sides(top, right, bottom, left).
Syntax:
p{
border: 1px solid red; margin:
size }
margin:40px
100px 120px;top
= 40px
right and
left = 100px
bottom =
120px
3. If the margin property has 2 values:
margin: 40px
100px; top and
bottom = 40px;
left and right =
100px;
CSS paddings are used to create space around the element, inside any defined border.
We can set different paddings for individual sides(top, right, bottom, left). It is important
to add border properties to implement padding properties.
INTERNAL CSS:
<!DOCTYPE html>
<html>
<head>
<style> body {
background-color: linen;
}
h1 {
color: maroon; margin-left: 40px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
EXTERNAL CSS:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1 style="color:blue;text-align:center;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
</body>
</html>
• PR-2-1.html
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8" />
<title>Jaitra's Personal Site</title>
<style>
body {
background-color: #eaf6f6;
}
hr {
border-color: grey;
border-style: none;
border-top-style: dotted;
border-width: 5px;
width: 5%;
}
h1 {
color: #66bfbf;
}
h3 {
color: #66bfbf;
}
</style>
</head>
<body>
<table cellspacing="20">
<tr>
<td>
<img
width="200"
height="200"
src="Images/circle-cropped-animoji-image.png"
alt="Earth Picture"
/>
</td>
<td>
<h1>Jaitra Patel</h1>
<p>
<em
>Just a student pursuing
<strong
><a href="https://en.wikipedia.org/wiki/Computer_engineering"
<hr />
<h3>Education</h3>
<ul>
<li>SSC from TERF.</li>
<li>Computer Engineering, Diploma from L.J. Polytechinc.</li>
<li>Pursuing Degree in Computer Engineering from A.I.T</li>
</ul>
<hr />
<h3>Study Experience</h3>
<table cellspacing="10">
<thead>
<tr>
<th>Dates</th>
<th>Study</th>
</tr>
</thead>
<tbody>
<tr>
<td>2017-2020</td>
<td>Completed Diploma</td>
</tr>
<tr>
<td>2020-2023</td>
<td>Pursuing Degree</td>
</tr>
</tbody>
<tfoot></tfoot>
</table>
<hr />
<h3>Skills</h3>
<table cellspacing="10">
<tr>
<td>Android Development ⭐⭐⭐ </td>
<td>Photography ⭐⭐</td>
</tr>
<hr />
<a href="#">My Hobbies</a>
<a href="#">Contact Me</a>
</body>
</html>
Output: -
• PR-2-2.html
<!DOCTYPE html>
<head>
<title>PR-2</title>
<style>
h2 {
color: #BDD2B6;
}
.classEx {
color: #A2B29F;
}
#idEx {
color: #798777;
}
</style>
</head>
<body>
<h2 class="classEx">This is class selector</h2>
<h2 id="idEx">This is id selector</h2>
<h2>This is simple h2 tag selector</h2>
</body>
</html>
Output: -
• PR-2-3.html
<!DOCTYPE html>
<head>
<title>PR-2</title>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even):hover {
background-color: #FEFBE7;
}
tr:nth-child(odd):hover {
background-color: #F7ECDE;
}
a:link{
color: #B4E197;
}
a:hover{
color: #83BD75;
}
a:visited{
color: #4E944F;
}
</style>
</head>
<body>
<table>
<tr>
<th>Heading-1</th>
<th>Heading-2</th>
<th>Heading-3</th>
</tr>
<tr>
<td>Sample Data-1</td>
<td>Sample Data-2</td>
<td><a href="#">Sample Data-3</a></td>
</tr>
Output: -
EVALUATION:
● Bootstrap is a free front-end framework for faster and easier web development
● Bootstrap includes HTML and CSS based design templates for typography,
forms, buttons, tables, navigation, modals, image carousels and many other, as
well as optional JavaScript plugins
● Bootstrap also gives you the ability to easily create responsive designs Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
The following example shows the code for a basic Bootstrap page (with a full width
container):
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<h1>My First Bootstrap Page</h1>
<p>This is some text.</p>
</div>
</body>
</html>
• PR-3-1.html
<!DOCTYPE html>
<head>
<title>Bootstrap Example</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Bootstrap Table Example</h2>
<table class="table">
<thead>
<tr>
<th>Heading-1</th>
<th>Heading-2</th>
<th>Heading-3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Sample Data-1</td>
<td>Sample Data-2</td>
<td>Sample Data-3</td>
</tr>
<tr>
<td>Sample Data-4</td>
<td>Sample Data-5</td>
<td>Sample Data-6</td>
</tr>
<tr>
<td>Sample Data-7</td>
<td>Sample Data-8</td>
<td>Sample Data-9</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
• PR-3-2.html
<!DOCTYPE html>
<head>
<title>Bootstrap Example</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Bootstrap List Example</h2>
<ul class="list-group">
<li class="list-group-item active">Sample List Item-1</li>
<li class="list-group-item">Sample List Item-2</li>
<li class="list-group-item">Sample List Item-3</li>
<li class="list-group-item">Sample List Item-4</li>
<li class="list-group-item">Sample List Item-5</li>
</ul>
</div>
</body>
</html>
Output: -
• PR-3-3.html
<!DOCTYPE html>
<head>
<title>Bootstrap Example</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Bootstrap Button Example</h2>
<a class="btn btn-primary btn-lg" href="#" role="button">Link</a>
<button class="btn btn-primary btn-sm" type="submit">Button</button>
<button type="button" class="btn btn-lg btn-primary" disabled>Primary
button</button>
<input class="btn btn-primary btn-sm" type="submit" value="Submit">
<button type="button" class="btn btn-outline-light">Light</button>
</div>
</body>
</html>
Output: -
QUIZ:
1. If you want to have 3 equal columns in Bootstrap, which class would you use?
Ans: - .col Class.
2. What Bootstrap version should you use if you need to support IE9?
Ans: - Bootstrap 3.
THEORY:
JAVASCRIPT
<!DOCTYPE html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function calculate(form) {
var num=parseInt(form.number.value); if (isNaN(num) || num < 0) {
form.result.value=(form.number.value + " is not a valid number! Try again!");
}
if (num == 1 || num == 2) { form.result.value=(num + " is prime!");
}
for (var i=2;i<num;i++) { if (num
% i == 0) { var prime="yes";
form.result.value=(num + " is not prime. It is divisible by " + i + "."); break;
}
if (num % i != 0) var prime="no";
}
if (prime == "no") form.result.value=(num + " is prime!");
}
</SCRIPT>
</head>
<body>
OUTPUT:
Validation Code:
function validateForm() {
var x = document.forms["myForm"]["fname"].value; if (x == "") {
alert("Name must be filled out"); return false;
}
}
1. Basic Validation: This warrants that all the mandatory fields are filled. It would
require just a loop through each field in the form and check for data.
2. Data Format Validation: Data validation checks the data for its correctness. Your
code must include appropriate logic to test the accuracy of data.
3. Empty field validation :
We have to create a function that returns whether validation is done or not ? function
validate_form ( )
{
valid = true;
if ( document.contact_form.contact_name.value == "" )
{
alert ( "Please fill in the 'Your Name' box." ); valid = false;
}
return valid;
Email Validation:
• PR-4-1.html
<!DOCTYPE html>
<head>
<title>PR-4</title>
<style>
.container {
display: flex;
justify-content: center;
align-items: center;
background-color: #FAF5E4;
margin-left: 25%;
margin-top: 50px;
width: 50%;
box-shadow: 5px 5px 5px 5px #EEEEEE;
}
.display-start {
text-align: left;
margin: 7px 0 7px 40px;
}
.center {
text-align: center;
}
.inp {
margin: 5px;
}
.btn {
padding: 7px 15px;
background-color: #F8ECD1;
box-shadow: 2px 2px #EEEEEE;
}
</style>
</head>
<body>
<div class="container">
<div class="center">
<h2>Registration Validation</h2>
<input class="inp" type="text" placeholder="Name" id="name" />
<br>
<p id="name-error"></p>
<br>
<input class="inp" type="email" placeholder="Email" id="email" />
<br>
<p id="email-error"></p>
<br>
<input class="inp" type="tel" placeholder="Phone" id="phone"
maxlength="10"/>
<br>
btn.addEventListener("click", function() {
let name = document.getElementById('name').value;
let phone = document.getElementById('phone').value;
let email = document.getElementById('email').value;
Output: -
• PR-4-2.html
<!DOCTYPE html>
<head>
<title>PR-4</title>
<style>
.container {
display: flex;
justify-content: center;
align-items: center;
background-color: #FAF5E4;
margin-left: 25%;
margin-top: 50px;
width: 50%;
box-shadow: 5px 5px 5px 5px #EEEEEE;
}
.display-div {
text-align: center;
}
.center {
text-align: center;
}
.inp {
margin: 5px;
}
.btn {
padding: 7px 15px;
background-color: #F8ECD1;
box-shadow: 2px 2px #EEEEEE;
}
</style>
</head>
<body>
<div class="container">
<div class="center">
<h2>Login</h2>
<input class="inp" type="text" placeholder="Username" id="uname" />
<br>
<p id="uname-error"></p>
<input class="inp" type="tel" placeholder="Phone" id="phone" />
<br>
<p id="phone-error"></p>
<input class="inp" type="text" placeholder="Password" id="pass" />
btn.addEventListener("click", function() {
let uname = document.getElementById('uname').value;
let pass = document.getElementById('pass').value;
let phone = document.getElementById('phone').value;
Output: -
• PR-4-3.html
<!DOCTYPE html>
<head>
<title>PR-4</title>
<style>
.container {
display: flex;
justify-content: center;
align-items: center;
background-color: #FAF5E4;
margin-left: 25%;
margin-top: 50px;
width: 50%;
box-shadow: 5px 5px 5px 5px #EEEEEE;
}
.display-div {
text-align: center;
}
.center {
text-align: center;
}
.inp {
margin: 5px;
}
.btn {
padding: 7px 15px;
background-color: #F8ECD1;
box-shadow: 2px 2px #EEEEEE;
}
</style>
</head>
<body>
<div class="container">
<div class="center">
<h2>Fibonacci Number</h2>
<input class="inp" type="text" placeholder="Enter Number"
name="number" id="number" />
<br>
<input type="button" name="submit" value="Generate" class="btn inp"
id="check"/>
<br>
</div>
</div>
<script>
btn.addEventListener("click", function() {
let num = Number(document.getElementById('number').value);
document.write("<strong>Fibonacci Series: </strong>");
for(let i = 1; i <= num; i++) {
document.write("<strong> " + n1 + " </strong>");
nextTerm = n1 + n2;
n1 = n2;
n2 = nextTerm;
}
});
</script>
</body>
</html>
Output: -
• PR-4-4.html
<!DOCTYPE html>
<head>
<title>PR-4</title>
<style>
p {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<p id="demo"></p>
<script>
var var1 = setInterval(inTimer, 1000);
var fs = 5;
var ids = document.getElementById("demo");
function inTimer() {
ids.innerHTML = "AHMEDABAD INSTITUTE OF TECHNOLOGY";
ids.setAttribute("style", "font-size: " + fs + "px; color: red");
fs += 5;
if (fs >= 50) {
clearInterval(var1);
var2 = setInterval(deTimer, 1000);
}
}
function deTimer() {
fs -= 5;
ids.innerHTML = "AHMEDABAD INSTITUTE OF TECHNOLOGY";
ids.setAttribute("style", "font-size: " + fs + "px; color: blue");
if (fs === 5) {
clearInterval(var2);
}
}
</script>
</body>
</html>
• PR-4-5.html
<!DOCTYPE html>
<body>
<img id="myImage" onclick="changeImage()" src="./images/pic_bulboff.gif"
width="100" height="180" alt="Example-images">
<script>
function changeImage() {
var image = document.getElementById('myImage');
if (image.src.match("bulbon")) {
image.src = "./images/pic_bulboff.gif";
} else {
image.src = "./images/pic_bulbon.gif";
}
}
</script>
</body>
</html>
Output: -
6. Is JavaScript case-sensitive?
Ans: - Yes.
EVALUATION:
THEORY:
PHP : Introduction
PHP started out as a small open source project that evolved as more and more people found
out how useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994.
PHP is a server side scripting language that is embedded in HTML. It is used to manage
dynamic content, databases, session tracking, even build entire e-commerce sites.
Syntax:
<?php
?>
Variable declaration:
<?php
$a = ‗abc‘;
$b = 123;
echo $a; // Print variable value
echo ‗second variable :‘.$b; // concatenation with .
?>
• PR-5-1.php
<?php
$alpha = range('A', 'Z');
$k = 0;
for($i=0; $i<=4; $i++)
{
for($j=0; $j<=$i; $j++)
{
echo $alpha[$j];
}
for($k=$i-1; $k>=0; $k--)
{
echo $alpha[$k];
}
echo "<br>";
}
?>
Output: -
• PR-5-2.php
<!DOCTYPE html>
<head>
<title>PR-5</title>
</head>
<body>
<form method="post">
Enter the Number:<br>
<input type="number" name="number" id="number">
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if($_POST)
{
$fact = 1;
$number = $_POST['number'];
</body>
</html>
Output: -
• PR-5-3.php
<!DOCTYPE html>
<head>
<title>PR-5</title>
</head>
<body>
<form method="post">
Enter the Number:<br>
<input type="number" name="number" id="number">
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if($_POST)
{
$fact = 1;
$number = $_POST['number'];
function armstrongCheck($num)
{
$sum = 0;
$x = $num;
while($x != 0)
{
$rem = $x % 10;
$sum = $sum + ($rem * $rem * $rem);
$x = $x / 10;
}
if($num == $sum)
{
return 1;
}
return 0;
}
$flag = armstrongCheck($number);
if($flag == 1)
{
echo $number . " is an Armstrong number";
} else {
echo $number . " is not an Armstrong number";
}
}
?>
</body>
</html>
• PR-5-4.php
<!DOCTYPE html>
<head>
<title>PR-5</title>
</head>
<body>
<form method="post">
Enter the Number:<br>
<input type="number" name="number" id="number">
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if($_POST)
{
$fact = 1;
$number = $_POST['number'];
function palindromeCheck($num)
{
$sum = 0;
$x = $num;
while(floor($x))
{
$rem = $x % 10;
$sum = $sum * 10 + $rem;
$x = $x / 10;
}
return $sum;
}
$palindrome = palindromeCheck($number);
if($palindrome == $number)
{
echo $number . " is an Palindrome number";
} else {
echo $number . " is not an Palindrome number";
}
}
?>
</body>
</html>
• PR-5-5.php
<!DOCTYPE html>
<head>
<title>PR-5</title>
<style>
.container {
display: flex;
justify-content: center;
align-items: center;
background-color: #FAF5E4;
margin-left: 25%;
margin-top: 50px;
width: 50%;
box-shadow: 5px 5px 5px 5px #EEEEEE;
}
.display-div {
text-align: center;
}
form {
text-align: center;
}
.inp {
margin: 5px;
}
.btn {
padding: 7px 15px;
background-color: #F8ECD1;
box-shadow: 2px 2px #EEEEEE;
}
</style>
</head>
<body>
<div class="container">
<form method="POST">
<h2>Login User</h2>
<input class="inp" type="text" placeholder="Username" name="uname"
/>
<br>
<input class="inp" type="text" placeholder="Password" name="pass"
/>
<br>
<input type="submit" name="submit" value="Register" class="btn inp"
/>
</form>
</div>
<?php
if($_POST)
{
Output: -
• PR-5-6.php
<!DOCTYPE html>
<head>
<title>PR-5</title>
<style>
.container {
display: flex;
justify-content: center;
align-items: center;
background-color: #FAF5E4;
margin-left: 25%;
margin-top: 50px;
width: 50%;
box-shadow: 5px 5px 5px 5px #EEEEEE;
}
.display-div {
text-align: center;
}
form {
text-align: center;
}
.inp {
margin: 5px;
}
.btn {
padding: 7px 15px;
background-color: #F8ECD1;
box-shadow: 2px 2px #EEEEEE;
}
</style>
</head>
<body>
<div class="container">
<form method="POST">
<h2>Login User</h2>
<input class="inp" type="text" placeholder="Username" name="uname"
/>
<br>
<input class="inp" type="text" placeholder="Password" name="pass"
/>
<br>
<input type="submit" name="submit" value="Register" class="btn inp"
/>
</form>
</div>
<?php
if($_POST)
Output: -
• PR-5-7.php
<!DOCTYPE html>
<head>
<title>PR-5</title>
<style>
.container {
display: flex;
justify-content: center;
align-items: center;
background-color: #FAF5E4;
margin-left: 25%;
margin-top: 50px;
width: 50%;
box-shadow: 5px 5px 5px 5px #EEEEEE;
}
.display-div {
text-align: center;
}
form {
text-align: center;
}
.inp {
margin: 5px;
}
.btn {
padding: 7px 15px;
background-color: #F8ECD1;
box-shadow: 2px 2px #EEEEEE;
}
</style>
</head>
<body>
<div class="container">
<form method="POST">
<h2>Date Difference</h2>
<input class="inp" type="date" placeholder="Enter date 1"
name="date1" />
<br>
<input class="inp" type="date" placeholder="Enter date 2"
name="date2" />
<br>
<input type="submit" name="submit" value="GIve Difference"
class="btn inp" />
</form>
</div>
<?php
if($_POST)
if($dateDiff % 2 == 0)
{
?>
<script>document.body.style.backgroundColor =
"#C4DDFF";</script>
<?php
} else {
?>
<script>document.body.style.backgroundColor =
"#FF6B6B";</script>
<?php
}
}
?>
</body>
</html>
Output: -
EVALUATION:
THEORY:
The readfile() function reads a file and writes it to the output buffer.
Assume we have a text file called "webdictionary.txt", stored on the server, that looks like
this: AJAX = Asynchronous JavaScript and XML
CSS = Cascading Style Sheets
HTML = HyperText Markup Language
PHP = PHP Hypertext Preprocessor
SQL = Structured Query Language
SVG = Scalable Vector Graphics
XML = EXtensible Markup Language
The readfile() function is useful if all you want to do is open up a file and read its contents.
A better method to open files is with the fopen() function. This function gives you more
options than the readfile() function.
The first parameter of fopen() contains the name of the file to be opened and the second
parameter specifies in which mode the file should be opened. The following example also
generates a message if the fopen() function is unable to open the specified file:
<?php
$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!"); echo
fread($myfile,file size("webdictionary.txt"));
fclose($myfile);
?>
• PR-6-1.php
<!DOCTYPE>
<html xml:lang>
<head>
<title>Login Page</title>
<style>
.container {
display: flex;
justify-content: center;
align-items: center;
background-color: #FAF5E4;
margin-left: 25%;
margin-top: 50px;
width: 50%;
box-shadow: 5px 5px 5px 5px #EEEEEE;
}
form {
text-align: center;
}
.inp {
margin: 5px;
}
.btn {
padding: 7px 15px;
background-color: #F8ECD1;
box-shadow: 2px 2px #EEEEEE;
}
</style>
</head>
<body>
<div class="container">
<form method="POST">
<h2>Login</h2>
<input class="inp uname" type="text" />
<br>
<input class="inp pass" type="text" />
<br>
<button class="inp btn login" type="button">Login</button>
</form>
</div>
<script>
let uname = document.querySelector(".uname");
let pass = document.querySelector(".pass");
let btn = document.querySelector(".login");
btn.addEventListener('click', function(){
console.log(uname.value, pass.uname)
if(uname.value === "admin" && pass.value === "admin123")
Output: -
• PR-6-2.php
<!DOCTYPE>
<html xml:lang>
<head>
<title>PR-6</title>
<style>
.header {
overflow: hidden;
background-color: #D5D5D5;
padding: 20px 10px;
}
.header a {
float: left;
color: black;
text-align: center;
padding: 12px;
text-decoration: none;
font-size: 18px;
line-height: 25px;
border-radius: 4px;
}
.header a.logo {
font-size: 25px;
font-weight: bold;
}
.header a:hover {
background-color: #ddd;
color: black;
}
.header a.active {
background-color: dodgerblue;
color: white;
}
.header-right {
float: right;
}
.footer-padding {
padding-bottom: 60px;
}
.footer {
.footer p {
margin-top: 25px;
font-size: 18px;
color: #fff;
}
</style>
</head>
<body>
<?php require "header.html"?>
<h1>Example of include</h1>
<?php require "footer.html"?>
</body>
</html>
Output: -
• PR-6-3.php
<!DOCTYPE>
<html xml:lang>
<head>
<title>PHP fgets() Example</title>
</head>
<body>
<form method="POST">
Enter String1 : <input type="text" name="str"> <br/>
Enter String2 : <input type="text" name="str1"> <br/> <br/>
<input type="submit" name="Submit1" value="Write File">
<input type="submit" name="Submit2" value="Read File - gets()">
</form>
<?php
if(isset($_POST['Submit1'])) {
$myfile = fopen("abc.txt", "a");
$text = $_POST["str"]. PHP_EOL . $_POST["str1"];
fwrite($myfile, $text);
fclose($myfile);
echo "file created !!";
}
if(isset($_POST['Submit2'])) {
$file=fopen("abc.txt","r");
$readfile=fgets($file);
echo $readfile;
fclose($file);
}
?>
</body>
</html>
Output: -
• PR-6-4.php
<!DOCTYPE>
<html xml:lang>
<head>
<title>PR-6</title>
<style></style>
</head>
<body>
<div class="container">
<form method="POST" enctype = "multipart/form-data">
<label>Select Image File:</label>
<input type="file" name="image"><br>
<label>Select PDF File:</label>
<input type="file" name="pdf"><br>
<input type="submit" name="submit" value="Upload">
</form>
<?php
if(isset($_POST['submit']))
{
$fileInfo = $_FILES['pdf']['tmp_name'];
$imageInfo = $_FILES['image']['tmp_name'];
$imageSize = filesize($imageInfo);
$allowedFileType = array('pdf');
$allowedImageType = array('jpeg', 'png');
$fileExtension = pathinfo($_FILES['pdf']['tmp_name']);
$imageExtension = pathinfo($_FILES['image']['tmp_name']);
EVALUATION:
THEORY:
What is an Exception?
Exceptions are a good way to stop a function when it comes across data that it cannot use.
Throwing an Exception
The throw statement allows a user defined function or method to throw an exception. When
an exception is thrown, the code following it will not be executed.
If an exception is not caught, a fatal error will occur with an "Uncaught Exception" message.
Lets try to throw an exception without catching it:
Example
<?php
To avoid the error from the example above, we can use the try...catch statement to catch
exceptions and continue the process.
Syntax
try {
} catch(Exception $e) {
The try...catch...finally statement can be used to catch exceptions. Code in the finally block
will always run regardless of whether an exception was caught. If finally is present, the catch
block is optional.
Syntax
try {
} catch(Exception $e) {
} finally {
• PR-7.php
<?php
function checkNum($number) {
if($number>1) {
throw new Exception("Value must be 1 or below");
}
return true;
}
try {
checkNum(2);
catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
}
?>
Output: -
EVALUATION:
THEORY :
What is a Session?
CREATING SESSION :
<?php
session_start(); //start the PHP_session function if(isset($_SESSION['page_count']))
{
$_SESSION['page_count'] += 1;
}
else
{
$_SESSION['page_count'] = 1;
}
echo 'You are visitor number ' . $_SESSION['page_count'];
?>
DESTROYING SESSION :
<?php
?>
?>
● Personalizing the user experience – this is achieved by allowing users to select their
preferences.
● The pages requested that follow are personalized based on the set preferences in the
cookies.
SET COOKIE :
<?php
?>
RETRIVE VALUE :
<?php
print_r($_COOKIE); //output the contents of the cookie array variable
?>
DELETE COOKIE:
<?php
?>
• PR-8-1.php
<!DOCTYPE html>
<head>
<title>PR-8</title>
</head>
<body>
<div class="container">
<form method="POST">
Username = <input type="text" name="uname"
<?php if(isset($_SESSION['uname'])) {echo "Welcome " .
$_SESSION['uname'];}?>
/><br>
<input type="checkbox" name="check" />remeber me<br>
<input type="submit" value="Create Session" name="btn"/>
</form>
<?php
if(isset($_POST['check']))
{
$_SESSION['uname'] = $_POST["uname"];
echo "Hello " . $_POST['uname'];
}
?>
</div>
</body>
</html>
Output: -
• PR-8-2.php
<?php
session_start();
?>
<!DOCTYPE html>
<head>
<title>PR-8-6</title>
</head>
<body>
<?php
$_SESSION['session'] = "Jaitra";
echo "Session Variable Is Set...";
?>
<br>
<?php
echo "Value is :- " . $_SESSION['session'];
?>
<br>
<?php
echo "Before Updating Session Variable...";
$_SESSION['session'] = "200020107537";
?>
<br>
<?php
echo "After Updating Session Variable...";
?>
<br>
<?php
echo "Latest Value :- " . $_SESSION['session'];
?>
<br>
<?php
echo "Removing session variable...";
session_unset();
?>
<br>
<?php
echo "Destroying Session...";
session_destroy();
?>
</body>
</html>
• PR-8-3.php
<?php
session_start();
if(isset($_SESSION['login']))
{
header("Location: PR-8-3-2.php");
exit();
}
?>
<!DOCTYPE>
<html xml:lang>
<head>
<title>Login Page</title>
<style>
.container {
display: flex;
justify-content: center;
align-items: center;
background-color: #FAF5E4;
margin-left: 25%;
margin-top: 50px;
width: 50%;
box-shadow: 5px 5px 5px 5px #EEEEEE;
}
form {
text-align: center;
}
.inp {
margin: 5px;
}
.btn {
padding: 7px 15px;
background-color: #F8ECD1;
box-shadow: 2px 2px #EEEEEE;
}
</style>
</head>
<body>
<div class="container">
<form method="get">
<h2>Login</h2>
<input class="inp uname" type="text" placeholder="Username"
name="uname" />
<br>
<input class="inp pass" type="text" placeholder="Password"
name="password" />
<br>
<input type="submit" name="submit" value="Login" class="btn inp" />
• PR-8-3-2.php
<?php
session_start();
?>
<!DOCTYPE>
<html xml:lang>
<head>
<title>Login Page</title>
<style>
.container {
display: flex;
justify-content: center;
align-items: center;
background-color: #FAF5E4;
margin-left: 25%;
margin-top: 50px;
width: 50%;
box-shadow: 5px 5px 5px 5px #EEEEEE;
}
form {
text-align: center;
}
.inp {
margin: 5px;
}
.btn {
padding: 7px 15px;
background-color: #F8ECD1;
box-shadow: 2px 2px #EEEEEE;
}
</style>
</head>
<body>
<div class="container">
<form method="POST">
Output: -
• PR-8-4.php
<?php
date_default_timezone_set("Indian/Maldives");
$time = date("H");
if($time < "12")
{
echo "Good Morning 🌅";
} else if($time >= "12" && $time <= "17")
{
echo "Good Afternoon 🌞";
} else if($time >= "17" && $time <= "19")
{
echo "Good Evening 🌅";
} else {
echo "Good Night 🌑";
}
?>
Output: -
• PR-8-5.php
<!DOCTYPE>
<html xml:lang>
<head>
<title>PR-6</title>
<style></style>
</head>
<body>
<div class="container">
<form method="POST" enctype = "multipart/form-data">
<label>Select PDF File:</label>
<input type="file" name="upload" id="upload"><br>
<input type="submit" name="submit" value="Upload">
</form>
<?php
if(isset($_POST['submit']))
{
$fileInfo = $_FILES['upload']['name'];
$allowedFileType = array('pdf');
$file_ext=strtolower(end(explode('.',$_FILES['upload']['name'])));
$fileSize = $_FILES['upload']['size'];
if(in_array($file_ext, $allowedFileType))
{
?>
<ul>
<li>Sent file: <?php echo "File Name :- " . $fileInfo; ?>
<li>File size: <?php echo "File Size :- " . $fileSize; ?>
<li>File type: <?php echo "File Extension :- " . $file_ext;
?>
</ul>
<?php
}
else
{
echo "Error File should only be in 'pdf'...!";
}
}
?>
</div>
</body>
</html>
• PR-8-6.php
<?php
session_start();
?>
<!DOCTYPE html>
<head>
<title>PR-8-6</title>
</head>
<body>
<?php
$_SESSION['session'] = "Jaitra";
echo "Session Variable Is Set...";
?>
<br>
<?php
echo "Value is :- " . $_SESSION['session'];
?>
<br>
<?php
echo "Before Updating Session Variable...";
$_SESSION['session'] = "200020107537";
?>
<br>
<?php
echo "After Updating Session Variable...";
?>
<br>
<?php
echo "Latest Value :- " . $_SESSION['session'];
?>
<br>
<?php
echo "Removing session variable...";
session_unset();
?>
<br>
<?php
echo "Destroying Session...";
session_destroy();
?>
</body>
</html>
QUIZ:
EVALUATION:
TITLE: Develop a program in PHP & JavaScript that demonstrate insert, update & delete
operation.
THEORY:
<?php
$connection_obj = mysqli_connect("{MYSQL_HOSTNAME}",
"{MYSQL_USERNAME}", "{MYSQL_PASSWORD}", "{MYSQL_DATABASE}");
?>
<?php
mysqli_select_db($connection_obj, "{MYSQL_DATABASE}");
?>
<?php
$query = "write your query here";
?>
• PR-9-1.php
<?php
?>
<!DOCTYPE html>
<head>
<title>PR-9</title>
<style>
.container {
display: flex;
justify-content: center;
align-items: center;
background-color: #FAF5E4;
margin-left: 25%;
margin-top: 50px;
width: 50%;
box-shadow: 5px 5px 5px 5px #EEEEEE;
}
.display-div {
text-align: center;
}
form {
text-align: center;
}
.inp {
margin: 5px;
}
.btn {
padding: 7px 15px;
background-color: #F8ECD1;
box-shadow: 2px 2px #EEEEEE;
}
</style>
</head>
<body>
<div class="container">
<form method="POST" action="PR-9-1-INSERT.php">
<h2>Register User</h2>
<input class="inp" type="text" placeholder="User ID" name="uid" />
<br>
<input class="inp" type="text" placeholder="Name" name="name" />
<br>
<input class="inp" type="tel" placeholder="Phone" name="phone" />
<br>
<input class="inp" type="text" placeholder="Password" name="pass"
/>
<br>
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "web_programming";
mysqli_close($conn);
?>
</div>
</div>
</body>
</html>
• PR-9-1-INSERT.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "web_programming";
if(isset($_POST['submit']))
{
$u_id = (int)$_REQUEST['uid'];
$u_name = $_REQUEST['name'];
$u_phone = (int)$_REQUEST['phone'];
$u_pass = $_REQUEST['pass'];
if(mysqli_query($conn, $sql))
{
mysqli_close($conn);
?>
• PR-9-1-UPDATE.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "web_programming";
if(isset($_POST['submit']))
{
$u_id = (int)$_REQUEST['uid'];
$u_name = $_REQUEST['name'];
$u_phone = (int)$_REQUEST['phone'];
$u_pass = $_REQUEST['pass'];
if(mysqli_query($conn, $sql))
{
echo '<script>alert("Recored Successfully Updated")</script>';
header("refresh:2; url=PR-9-1.php");
} else {
echo 'ERROR: -' . mysqli_error($conn);
}
}
mysqli_close($conn);
?>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "web_programming";
if(isset($_POST['submit']))
{
$u_id = (int)$_REQUEST['uid'];
if(mysqli_query($conn, $sql))
{
echo '<script>alert("Recored Successfully Deleted")</script>';
header("refresh:2; url=PR-9-1.php");
} else {
echo 'ERROR: -' . mysqli_error($conn);
}
}
mysqli_close($conn);
?>
Output: -
• PR-9-2.php
<?php
?>
<!DOCTYPE html>
<head>
<title>PR-9</title>
<style>
.container {
display: flex;
justify-content: center;
align-items: center;
background-color: #FAF5E4;
margin-left: 25%;
margin-top: 50px;
width: 50%;
box-shadow: 5px 5px 5px 5px #EEEEEE;
}
.display-div {
text-align: center;
}
form {
text-align: center;
}
.inp {
margin: 5px;
}
.btn {
padding: 7px 15px;
background-color: #F8ECD1;
box-shadow: 2px 2px #EEEEEE;
}
</style>
</head>
<body>
<div class="container">
<form method="POST">
<h2>Login User</h2>
<input class="inp" type="text" placeholder="Username" name="uname"
/>
<br>
<input class="inp" type="text" placeholder="Password" name="pass"
/>
<br>
<input type="submit" name="submit" value="Login" class="btn inp" />
</form>
</div>
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "web_programming";
if(isset($_POST['submit']))
{
$u_name = $_REQUEST['uname'];
$u_pass = $_REQUEST['pass'];
if($result->num_rows > 0)
{
echo '<script>alert("Login Successfully...!")</script>';
} else {
echo '<script>alert("Invalid Login Details...!")</script>';
}
}
mysqli_close($conn);
?>
</div>
</body>
</html>
Output: -
THEORY:
What is AJAX?
In short, AJAX is about loading data in the background and displaying it on the webpage,
without reloading the whole page.
Examples of applications using AJAX: Gmail, Google Maps, Youtube, and Facebook tabs.
What is jQuery?
jQuery is a lightweight, "write less, do more", JavaScript library.
The purpose of jQuery is to make it much easier to use JavaScript on your website.
jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish,
and wraps them into methods that you can call with a single line of code.
jQuery also simplifies a lot of the complicated things from JavaScript, like AJAX calls and
DOM manipulation.
• DOM manipulation
• CSS manipulation
• HTML event methods
• Effects and animations
• AJAX
• Utilities
The jQuery snippets below demonstrate different ways to make Ajax requests.
$.ajax({
url : post_url,
type: request_method,
da
ta : form_data
}).done(function(response){ //
$("#server-results").html(response);
});
});
The .serialize() method serializes a form input to a query string that could be sent using Ajax.
• PR-10-1.php
<!DOCTYPE html>
<head>
<title>PR-10</title>
<style>
.container {
display: flex;
justify-content: center;
align-items: center;
background-color: #FAF5E4;
margin-left: 25%;
margin-top: 50px;
width: 50%;
box-shadow: 5px 5px 5px 5px #EEEEEE;
}
.display-div {
text-align: center;
}
form {
text-align: center;
}
.inp {
margin: 5px;
}
.btn {
padding: 7px 15px;
background-color: #F8ECD1;
box-shadow: 2px 2px #EEEEEE;
}
</style>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("form").on("submit", function(event) {
event.preventDefault();
• PR-10-1-2.php
<?php
$uname = $_POST['uname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$pass = $_POST['pass'];
$unameRegEx = '/^[A-Za-z][A-Za-z0-9]{5,31}$/';
$phoneRegEx = '/^[6-9]\d{9}$/';
$passRegEx = '/^.{6,}$/';
Output: -
• PR-10-2.php
<!DOCTYPE html>
<head>
<title>PR-10</title>
<style>
@import url("https://fonts.googleapis.com/css?family=Open+Sans");
body {
font-family: "Open Sans";
font-size: 14px;
}
.container {
display: flex;
justify-content: start;
align-items: center;
background-color: #FAF5E4;
margin: 25px auto;
width: 500px;
padding: 20px;
box-shadow: 5px 5px 5px 5px #EEEEEE;
}
form label {
border: 0;
margin-bottom: 3px;
display: block;
width: 100%;
}
form .error {
color: #ff0000;
}
form .inp {
border-radius: 4px;
display: block;
width: 100%;
margin: 5px 0;
height: 25px;
line-height: 25px;
background: #fff;
color: #000;
padding: 0 6px;
box-sizing: border-box;
}
.btn {
border-radius: 4px;
margin-top: 5px;
padding: 7px 15px;
background-color: #F8ECD1;
box-shadow: 2px 2px #EEEEEE;
Output: -