Sei sulla pagina 1di 30

WEB PROGRAMMING LAB MANUAL

1. Develop and demonstrate a XHTML document that illustrates the use external style
sheet, ordered list, table, borders, padding, color, and the tag.
Prg1.html
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC="-/W3C//DTD XHTML 1.1//EN"
http://www.w3.org/TR/xhtml 1.1/DTD/xhtml11.dtd>
<html xmlns="http://www.w3.org/1999</xhtml">
<head>
<title>program1</title>
<link rel="stylesheet" type="text/css" href="prg1a.css" />
</head>
<body bgcolor="aqua">
<p>ordered list </p>
<ol>
<li>india</li>
<li>pakistan</li>
<li>china</li>
</ol>
<table cellspacing="6" cellpadding=5 border="6">
<tr>
<th> </th>
<td style="color:green">GOLD</td>
<td style="color:red">SILVER</td>
<td style="color:blue">BRONZE</td>
</tr>
<tr>
<td style="color:green">INDIA</td>
<td>0</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td style="color:yellow">CHINA</td>
<td>0</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td style="color:red">JAPAN</td>
<td>1</td>

CSE, CITECH

Page 1

WEB PROGRAMMING LAB MANUAL


<td>0</td>
<td>2</td>
</table>
<p>
when we plan for <span class="spanred">
saving our hard earned money</span>,our focus is always to ensure that they are good.
</P>
</body>
</html>
Prg1a.css
P
{font-family:Times New roman;
font-size:10pt;
font-variant:normal;
font-style:italic;
font-weight:bolder;
text-decoration:underline;
text-indent:0.5in;
color:red;
}
.spanred {font size:16pt;
font-weight:ligher;
color:green; }
OUTPUT:

CSE, CITECH

Page 2

WEB PROGRAMMING LAB MANUAL


2. Develop and demonstrate a XHTML file that includes Javascript script for the following
problems: a) Input: A number n obtained using prompt
Output: The first n Fibonacci numbers
Prg2a.html
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC="-/W3C//DTD XHTML 1.1//EN"
http://www.w3.org/TR/xhtml 1.1/DTD/xhtml11.dtd>
<html xmlns="http://www.w3.org/1999</xhtml">
<head><title>fibonacci 2.a</title>
</head>
<body>
<script type="text/javascript">
var a=0;
var b=1;
var c,i;
var n=prompt("enter a number"," ");
while(n<=0)
{
alert("enter the nos");
n=prompt("enter a number"," ");
}
document.write("fibonacci series<br />");
document.write(a,"<br />");
document.write(b,"<br />");
for(i=0;i<n-2;i++)
{
c=a+b;
document.write(c,"<br />");
a=b;
b=c;
}
</script>
</body>
</html>
INPUT:
OUTPUT:
Enter the Numbers
0
3
1
1

CSE, CITECH

Page 3

WEB PROGRAMMING LAB MANUAL


2 b) Input:

A number n obtained using prompt

Output: A table of numbers from 1 to n and their squares using alert


Prg2b.html
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC="-/W3C//DTD XHTML 1.1//EN"
http://www.w3.org/TR/xhtml 1.1/DTD/xhtml11.dtd>
<html xmlns="http://www.w3.org/1999</xhtml">
<head><title> exercisse2.b </title>
</head>
<body>
<script type="text/javascript">
var n=prompt("enter a positive value for n", );
while(n<=0)
{
alert("enter positive value");
n=prompt("enter positive value for n"," ");
}
var str="numbers and their square \n";
document.write("numbers and their square values using alert <br />");
for(i=1;i<=n;i++)
{
str=(str+i+"==>"+i*i+"\n");
}
alert(str);
</script>
</body>
INPUT:
Enter the Numbers
4
OUTPUT:

CSE, CITECH

Page 4

WEB PROGRAMMING LAB MANUAL


3. Develop and demonstrate a XHTML file that includes Javascript script that uses
functions for the following problems:
a)
Parameter: A string
Output: The position in the string of the left-most vowel
Prg3a.html
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC="-/W3C//DTD XHTML 1.1//EN"
http://www.w3.org/TR/xhtml1.1/DTD/xhtml11.dtd>
<html xmlns="http://www.3.org/1999/xhtml">
<head><title> position3.a</title>
</head>
<body bgcolor="aqua">
<script type="text/javascript">
var str=prompt("enter a string");
var i;
document.write("the given string is:",str," <br \>");
var len=str.length;
for(i=0;i<len;i++)
{
if(str.charAt(i)=='a' || str.charAt(i)=='e' || str.charAt(i)=='i' || str.charAt(i)=='o' || str.charAt(i)=='u'
|| str.charAt(i)=='A' || str.charAt(i)=='E' || str.charAt(i)=='I' || str.charAt(i)=='O' ||
str.charAt(i)=='U')
{
document.write("<br> <h3> the position of left most vowel in the given string is:"+(i+1)+"
vowel is: "+str.charAt(i)+" </h3></br>");
var flag=1;
break;
}
}
if(!flag)
document.write("vowel is not present");
</script>
</body>
</html>
INPUT:
Enter the String:
City College
OUTPUT:
The given String is: City College
The Position of the left most vowels in the given string is: 2

CSE, CITECH

Page 5

WEB PROGRAMMING LAB MANUAL


3 b) Parameter: A number
Output: The number with its digits in the reverse order
Prg3b.html
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC="-/W3C//DTD XHTML 1.1//EN"
http://www.w3.org/TR/xhtml1.1/DTD/xhtml11.dtd>
<html xmlns="http://www.w3.org/1999/xhtml">
<head> <title> exerise 3b </title> </head>
<body bgcolor="blue">
<script type="text/javascript">
var r=0,d,f=0,n=prompt("enter value for n");
if(n<0)
{
f=1;
n=n*-1;
}
var alph;
alph=isNaN(n);
while(alph)
{
alert("this is not a numbr");
n=prompt("enter value for n");
alph=isNaN(n);
}
document.write("the given number is :",n," <br />");
do
{
d=n%10;
n=parseInt(n/10);
r=r*10+d;
}
while(n>0)
if(f==0)
document.write("reverse of given numbers is ",r," <br />");
</script>
</body>
</html>
INPUT: Enter the Number is: 789
OUTPUT:

CSE, CITECH

Page 6

WEB PROGRAMMING LAB MANUAL


4. a) Develop and demonstrate, using Javascript script, a XHTML document that collects
the USN ( the valid format is: A digit from 1 to 4 followed by two upper-case characters
followed by two digits followed by two upper-case characters followed by three digits; no
embedded spaces allowed) of the user. Event handler must be included for the form
element that collects this information to validate the input. Messages in the alert windows
must be produced when errors are detected.
b) Modify the above program to get the current semester also (restricted to be a number
from 1 to 8)
prg4a.html
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC="-/W3C//DTD XHTML 1.1//EN"
http://www.w3.org/TR/xhtml 1.1/DTD/xhtml11.dtd>
<html xmlns="http://www.w3.org/1999/xhtml">
<head> <title> exercise 4a</title>
<body bgcolor="green"></body>
<script type="text/javascript">
function chkusn()
{
var myusn=document.getElementById("usn");
var pos=myusn.value.search(/^[1-4][A-Z][A-Z]\d{2}[A-Z][A-Z]\d{3}$/);
if(myusn.value==" ")
{
alert("enter the USN:");
usn.focus();
}
if(pos!=0)
{
alert("the format is not correct!!!");
usn.focus();
usn.select();
return false;
}
else
{
alert("...the format is correct..");
return true;
}
}
</script>

CSE, CITECH

Page 7

WEB PROGRAMMING LAB MANUAL


</head>
<body>
<h3> validation example </h3></br /><br /><br />
<p> example to check the format of data entered in the txt box </p> <br /> <br /><br />
<form action=" ">
<p> usn:<input type="text" id="usn" /> <br /><br /><br />
<input type="submit" id="submit" value="submit" />
</p>
</form>
<script typ="text/javascript">
document.getElementById("submit").onclick=chkusn;
</script>
</body>
</html>
INPUT:
Enter the USN: 2AB09CS001
OUTPUT:

CSE, CITECH

Page 8

WEB PROGRAMMING LAB MANUAL


4b) Modify the above program with semester
Prg4b.html
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-/W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml1.1/DTD/xhtml11.dtd>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>exercise 4b</title>
<body bgcolor="brown"></body>
<script type="text/javascript">
function chkusn()
{
var myusn=document.getElementById("usn");
var pos=myusn.value.search(/^[1-4][A-Z][A-Z]\d{2}[A-Z][A-Z]\d{3}$/);
var mysem=document.getElementById("sem");
var pos1=mysem.value.search(/^[1-8]$/);
if(myusn.value==" "||mysem.value==" ")
{
alert("enter the usn:");
usn.focus();
sem.focus();
}
if(pos!=0 || pos1!=0)
{
alert("the format is not correct@!!!!!!");
usn.focus();
usn.select();
sem.focus();
sem.select();
return false;
}
else
{
alert("the format is correct");
return true;
}
}
</script>
</head> <body>

CSE, CITECH

Page 9

WEB PROGRAMMING LAB MANUAL


<h3>validation example</h3></br /><br /><br />
<p>example to check the format of data entered in the text box</p><br /><br /><br />
<form action=" ">
<p>usn:<input type="text" id="usn"/><br /><br /><br />
sem:<input type="text" id="sem"/><br /><br /><br />
<input type="submit" id="submit" value="submit"/>
</p>
</form>
<script type="text/javascript">
document.getElementById("submit").onclick=chkusn;
</script>
</body>
</html>
INPUT:
Enter the USN and SEM: 2AB09CS001 and 2.

OUTPUT:

CSE, CITECH

Page 10

WEB PROGRAMMING LAB MANUAL


5.a) Develop and demonstrate, using Javascript script, a XHTML document that contains
three short paragraphs of text, stacked on top of each other, with only enough of each
showing so that the mouse cursor can be placed over some part of them. When the cursor
is placed over the exposed part of any paragraph, it should rise to the top to become
completely visible.
Prg5a.html
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Stacking</title>
<script type="text/javascript">
function bringThisUp(div1,div2,div3)
{
document.getElementById("paragraph1").style.zIndex = div1;
document.getElementById("paragraph2").style.zIndex = div2;
document.getElementById("paragraph3").style.zIndex = div3;
}
</script>
<style type="text/css">
.paragraph
{
border: solid 4px;
width:4in;
height: 3in;
position: absolute;
}
#paragraph1
{
left: 3in;
top: 3in;
z-index: 0;
border-color: red;
background-color: orange;
}
#paragraph2
{
left: 3.5in;
top: 3.5in;
z-index: 1;
border-color: green;
background-color: white;
}
#paragraph3
{

CSE, CITECH

Page 11

WEB PROGRAMMING LAB MANUAL


left: 4in;
top: 4in;
z-index: 2;
border-color: blue;
background-color: green;
}
</style>
</head>
<body bgcolor="grey" text="black" >
<h1> <marquee> Program #5a </marquee> </h1>
<center><h3>XHTML Document to illustrate to Stacking(Z-Index) using
CSS</h3>
<h4>City Engineering College</h4>
<h5>Dept. of Information Science and Engineering</h5></center>
<hr>
<h3>XHTML document to illustrate z-index using Javascript</h3>
<div id="paragraph1" class="paragraph" onmouseover="bringThisUp(2,0,1)"
align="center"><br /><br />
Welcome to Bangalore</div>
<div id="paragraph2" class="paragraph" onmouseover="bringThisUp(0,2,1)"
align="center"><br /><br />
Welcome to CEC</div>
<div id="paragraph3" class="paragraph" onmouseover="bringThisUp(0,1,2)"
align="center"><br /><br />
Welcome to ISE Dept.</div>
</body></html>

OUTPUT:

Hi welcome to Bangalore
Hi welcome to
CEC
Welcome
to ISE
Dept.

CSE, CITECH

Page 12

WEB PROGRAMMING LAB MANUAL


b) Modify the above document so that when a paragraph is moved from the top stacking
position, it returns to its original position rather than to the bottom.
Prg5b.html
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Stacking</title>
<script type="text/javascript">
var curIndex;
function bringThisUp(currDiv)
{
var myDiv = document.getElementById(currDiv);
curIndex = myDiv.style.zIndex;
myDiv.style.zIndex = "3";
}
function sendThisBack(currDiv)
{
var myDiv = document.getElementById(currDiv);
myDiv.style.zIndex = curIndex;
}
</script>
<style type="text/css">
.paragraph
{
border: solid 4px;
width: 3in;
height: 3in;
position: absolute;
}
#paragraph1
{
left: 3in;
top: 3in;
z-index: 0;
border-color: red;
background-color: orange;
}
#paragraph2
{
left: 3.5in;
top: 3.5in;
z-index: 1;
border-color: green;
background-color: white;

CSE, CITECH

Page 13

WEB PROGRAMMING LAB MANUAL


}
#paragraph3
{
left: 4in;
top: 4in;
z-index: 2;
border-color: blue;
background-color: green;
}
</style> </head>
<body bgcolor="black" text="yellow" >
<h1> <marquee> Program #5b </marquee> </h1>
<center><h3>XHTML Document to illustrate to Stacking(Z-Index) Position
using CSS</h3>
<h4>City Engineering College</h4>
<h5>Dept. of Computer Science and Engineering</h5></center>
<hr>
<h3>XHTML document to illustrate z-index using Javascript</h3>
<div id="paragraph1" class="paragraph" onmouseover="bringThisUp(this.id)"
onmouseout="sendThisBack(this.id)">
Welcome to Bnagalore </div>
<div id="paragraph2" class="paragraph" onmouseover="bringThisUp(this.id)"
onmouseout="sendThisBack(this.id)">
Welcome to CEC </div>
<div id="paragraph3" class="paragraph" onmouseover="bringThisUp(this.id)"
onmouseout="sendThisBack(this.id)">
Welcome to ISE Dept.
</div> </body> </html>
OUTPUT:
Welcome to Bangalore

Welcome to CEC

ISE

CSE, CITECH

Page 14

WEB PROGRAMMING LAB MANUAL


6. a) Design an XML document to store information about a student in an engineering
college affiliated to VTU. The information must include USN, Name, Name of the College,
Brach, Year of Joining, and e-mail id. Make up sample data for 3 students. Create a CSS
style sheet and use it to display the document.
Prg6a.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/css" href="pg6a.css" ?>
<studentlist>
<student>
<usn> 1CE07CS042</usn>
<name>GOPAL </name>
<college> City Engineering College </college>
<branch> COMPUTER SCIENCE </branch>
<joindate> 20-july-2007 </joindate>
<emailid> gopal.j@gmail.com </emailid>
</student>
<student>
<usn> 1CE07IS086</usn>
<name> kashi </name>
<college> City Engineering College </college>
<branch> INFORMATION SCIENCE </branch>
<joindate> 26-june-2009 </joindate>
<emailid> kashi67.g@gmail.com </emailid>
</student>
<student>
<usn> 1CE07EC056</usn>
<name> madhu </name>
<college> City Engineering College </college>
<branch> ELECTRONICS </branch>
<joindate> 9-mar-2002 </joindate>
<emailid> mad.78@gmail.com </emailid>
</student>
</studentlist>

CSE, CITECH

Page 15

WEB PROGRAMMING LAB MANUAL


pg6a.css
student{display:block;margin-top:15px;color:blue;}
usn{display:block;color:maroon;margin-top:15px;font-sixe:16pt;}
name{display:block;color:green;margin-top:15px;font-sixe:12pt;}
college{display:block;color:red;margin-top:15px;font-sixe:12pt;}
branch{display:block;color:yellow;margin-top:15px;font-sixe:12pt;}
joindate{display:block;color:aqua;margin-top:15px;font-sixe:12pt;}
emailid{display:block;color:green;margin-top:15px;font-sixe:12pt;}
OUTPUT:
1CE07IS001
SOW
CEC
ISE
09-05-2007
sow@gmail.com
1CE07IS002
SHEELA
CEC
ISE
09-06-2007
sheela@gmail.com
6 b) Create an XSLT style sheet for one student element of the above document and use it
to create a display of that element.
Prg6b.xml
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="http://localhost/pg6b.xsl"?>
<VTU>
<USN> 1CE08CS045 </USN>
<name> kavya </name>
<college>CEC </college>
<branch> CSE </branch>
<YOJ> 2007 </YOJ>
<email> kavya89.s@gmail.com </email>
</VTU>

CSE, CITECH

Page 16

WEB PROGRAMMING LAB MANUAL


Prg6b.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="VTU">
<html>
<body bgcolor="pink" text="yellow">
<h1><marquee>program 6b</marquee></h1>
<center><h3>XML Document using XSL</h3>
<h4>CEC</h4>
<h5>Dept. of ISE</h5></center>
<hr/>
<h3>VTU student from XML to XSLT</h3>
<span style="font-style:italic;color:blue;">USN:</span><xsl:value-of select="USN"/><br/>
<span style="font-style:italic;color:blue;">NAME:</span><xsl:value-of select="name"/><br/>
<span style="font-style:italic;color:blue;">College:</span><xsl:value-of
select="college"/><br/>
<span style="font-style:italic;color:blue;">BRANCH:</span><xsl:value-of
select="branch"/><br/>
<span style="font-style:italic;color:blue;">YOJ:</span><xsl:value-of select="YOJ"/><br/>
<span style="font-style:italic;color:blue;">E-MAIL:</span><xsl:value-of select="email"/><br/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
OUTPUT:

CSE, CITECH

Page 17

WEB PROGRAMMING LAB MANUAL

7. a) Write a Perl program to display various Server Information like Server Name, Server
Software, Server protocol, CGI Revision etc.
Prg7a.html
<html>
<head><title>Server info</title></head>
<body>
<form action="http://localhost/cgi-bin/prg7a.pl" method="post">
<h1>Server info display pgm</h1>
<input type="submit" value="click here to see info">
</form>
</body>
</html>
Prg7a.pl
#!/usr/bin/perl
print"content-type:text/html","\n\n";
printf"<html><body> <h1 align=center> server information </h1> <br />";
print"<h3><br>server name:- ",$ENV{'SERVER_NAME'};
print"<br> RUNNING PORT:- ",$ENV{'SERVER_PORT'};
print"<br> SERVER PROTOCOL:- ",$ENV{'SERVER_PROTOCOL'};
print"<br> SERVER SOFTWARE:- ",$ENV{'SERVER_SOFTWARE'};
print"<br> GATEWAY INTERFACE:- ",$ENV{'GATEWAY_INTERFACE'};
print"<br> </h3> </body> </html>";
OUTPUT:
SERVER INFORMATIOM
SERVAER NAME: localhost
SERVAER PORT: 80
SERVAER PROTOCOL: HTTP/1.1
SERVAER SOFTWARE: Apache/2.2.12
GATEWAY INTERFACE: CGI

CSE, CITECH

Page 18

WEB PROGRAMMING LAB MANUAL


7 b) Write a Perl program to accept UNIX command from a HTML form and to display
the output of the command executed.
prg7b.html
<html>
<head><title>UNIX COMMANDS</title></head>
<body bgcolor="green">
<form action="http://localhost/cgi-bin/prg7b.pl" method="get">
<input type="text" name="command">
<input type="submit" value="execute">
<input type="reset" value="clear">
</form>
</body>
</html>
Prg7b.pl
#!/usr/bin/perl
use CGI":standard";
print"content-type:text/html","\n\n";
$input=param(command);
print"";
print"<html><body><h1>command result</h1><br>command executed:",$input;
#system($input);
print`$input`;
print"</body></html>";
OUTPUT:
COMMAND result:
Command executed: date Fri Jul 29 11:01:55 IST 2011

CSE, CITECH

Page 19

WEB PROGRAMMING LAB MANUAL


8. a) Write a Perl program to accept the User Name and display a greeting message
randomly chosen from a list of 4 greeting messages.
Prg8a.pl
#!/usr/bin/perl
use CGI ":standard";
print "content-type:text/html","\n\n";
$input=param(username);
print"<h1>hi</h1>",$input;
my @msgs=("GOOD DAY!!","@@@@WELCOME@@@@","FINE DAY","...BEST
WISES");
print "<h1>";
print $msgs[int rand scalar@msgs];
print "</h1>--visit soon........";
OUTPUT:
HI!
FINE DAY
visit soon.

HI!
GOOD DAY..!!
visit soon.

8 b) Write a Perl program to keep track of the number of visitors visiting the web page and
to display this count of visitors, with proper headings
prg8b.pl
#!/usr/bin/perl
print"Content-type:text/html","\n\n";
print "<html><body><h1>no of visits to this page....</h1><br />";
$file='color.txt';
open(INFO,$file);
$n=<INFO>;
close(INFO);
print"<h1>$n</h1>";
open INFO,">color.txt";
print INFO ++$n;
close INFO;
print "<br></body></html>";
OUTPUT:
Number of Visits to this Page 5

CSE, CITECH

Page 20

WEB PROGRAMMING LAB MANUAL


9. Write a Perl program to display a digital clock which displays the current time of the
server.
Prg9.pl
#!/usr/bin/perl
use CGI":standard";
$de=1;
print "refresh:",$de,"\n";
print "Content-type:text/html","\n\n";
print "<html><body bgcolor=#ffaaaa>DIGITAL CLOCK<br>";
($s,$m,$h)=localtime(time);
print"<br><br>The current system time is $h hours $m minutes $s seconds";
print "</body></html>";
OUTPUT:
DIGITAL CLOCK
The Current System time is 12 hours 53 minutes 47 seconds
10 Write a Perl program to insert name and age information entered by the user into a
table created using MySQL and to display the current contents of this table.
Prg10.html
<html>
<head>
<title>CONNECTION TO MYSQL</title>
</head>
<body>
<h1 align=center>enter your information:</h1>
<form action="http://localhost/cgi-bin/prg10.pl" method="post">
<p><b>NAME:<input type="text" name="name"><br /><br />
<b>AGE:<input type="text" name="age"><br /><br />
<input type="submit">
</p>
</form>
</body>
</html>

CSE, CITECH

Page 21

WEB PROGRAMMING LAB MANUAL


Prg10.pl
#!/usr/bin/perl
use CGI":standard";
use DBI;
print "content-type:text/html","\n\n";
print "<html><title>connection</title><body><br />";
$name=param("name");
$age=param("age");
$dbh=DBI->connect("DBI:mysql:web","root","");
$sql="insert into age_info values('$name','$age')";
$qh=$dbh->prepare($sql);
$qh->execute();
print "<br />information is successfully inserted into the database</body></html>";
$qh->finish();
$sql="select * from age_info";
$sth=$dbh->prepare($sql);
$sth->execute();
print "<h1>contents of the table is..</h1><table align=center border=1>";
print "<tr><th>Name</th>";
print "<th>age</th></tr>";
while(($name,$age)=$sth->fetchrow())
{
print "<tr><td>$name</td><td>$age</td></tr>";
}
print "</table>";
$dbh->disconnect();
OUTPUT:
Enter your Information

Information is successfully inserted into the database


A content of the table is...
Name
Sow
Sheela
Anugana

CSE, CITECH

Age
22
21
13

Page 22

WEB PROGRAMMING LAB MANUAL


11. Write a PHP program to store current date-time in a COOKIE and display the Last
visited on date-time on the web page upon reopening of the same page.
Prg11.php
<?php
date_default_timezone_set('Asia/calcutta');
$inTwoMonths=60*60*24*60+time();
setcookie('lastVisit',date("G:i-m/d/y"),$inTwoMonths);
if(isset($_COOKIE['lastVisit']))
{
$visit=$_COOKIE['lastVisit'];
echo "your last visit was-".$visit;
}
else
echo "Yu've got some stale cookies!";
?>
OUTPUT:

12. Write a PHP program to store page views count in SESSION, to increment the count on
each refresh, and to show the count on web page.
Prg12.php
<?
session_start();
session_register("count");
if(!isset($_SESSION))
{
$_SESSION["count"]=0;
echo "<p>counter initiazed</p>\n";
}
else {$_SESSION["count"]++;}
echo "<p>the counter is now <b>$_SESSION[count]</b></p>","<p>reload this page to
increment</p>";
?>
OUTPUT:
The Counter is now 12
Reload this page to increment

CSE, CITECH

Page 23

WEB PROGRAMMING LAB MANUAL


13. Create a XHTML form with Name, Address Line 1, Address Line 2, and E-mail text
fields. On submitting, store the values in MySQL table. Retrieve and display the data based
on Name.
prg13.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Mysql</title>
</head>
<body bgcolor="pink" text="yellow">
<h1><marquee>program#14</marquee></h1>
<center><h3>XHTML Document to use of PHP & MYSQL</h3>
<h4>City Engineering College</h4>
<h5>Dept of Computer Science and engineering</h5></center>
<hr>
<h1 align="center">Form to insert values into table</h1>
<form action="prg13a.php">
<table border="1"align="center">
<tr> <td>NAME:</td>
<td><input type="text"id="name"name="name"/></td>
</tr>
<tr>
<td>ADDR1:</td>
<td><input type="text"id="addr1"name="addr1"/></td>
</tr>
<tr>
<td>ADDR2:</td>
<td><input type="text"id="addr2"name="addr2"/></td>
</tr>
<tr>
<td>EMAIL:</td>
<td><input type="text" id="email" name="email"/></td>
</tr>
<tr>
<td><input type="submit"value="submit"/></td>
<td><input type="reset"value="reset"/></td>
</tr>
</form>
</table>
<hr/>

CSE, CITECH

Page 24

WEB PROGRAMMING LAB MANUAL


<h1 align="center">Form to retrieve values based on Title</h1>
<form action="prg13b.php">
<table border="1" align="center">
<tr>
<td>NAME:</td>
<td><input type="text" id="name" name="name"/></td>
</tr>
<tr>
<td><input type="submit" value="submit"/></td>
<td><input type="reset" value="reset"/></td>
</tr>
</form>
</table>
</body>
</html>
Prg13a.php
<?php
$name=$_GET["name"];
$addr1=$_GET["addr1"];
$addr2=$_GET["addr2"];
$email=$_GET["email"];
$mysql=mysql_connect("localhost","root","") or die("cannot connect");
$query="insert into student values('$name','$addr1','$addr2','$email')";
mysql_db_query("CEC",$query) or die("error in inserting");
print"<body bgcolor='yellow' text ='black'>
<h1><marquee>program#13</marquee></h1>
<center><h3>XHTML Document to use of PHP & MYSQL</h3>
<h4>City Engineering College</h4>
<h5>Dept of Computer Science and engineering</h5></center>
<hr><center>successfully inserted!</center>";
$query="select * from student";
$result=mysql_db_query("CEC",$query)
or die("error in selecting");
print"<br/>";
print"<table border=1>";
while($array=mysql_fetch_row($result))
{
print"<tr>";
foreach($array as $f)

CSE, CITECH

Page 25

WEB PROGRAMMING LAB MANUAL


{
print"<td>";
print"$f";
print"</td>";
}
print"</tr>";
}
print"</table>";
mysql_close($mysql);
?>

Prg13b.php
<?php
$name=$_GET['name'];
$mysql=mysql_connect("localhost","root","") or die("cannot connect");
$query="select * from student where name='$name'";
$result=mysql_db_query("CEC",$query) or die("error in the query");
print"<html><body bgcolor='black' text='yellow'>
<h1><marquee>program#13</marquee></h1>
<center><h3>XHTML Document to use of PHP & MYSQL</h3>
<h4>City Engineering College</h4>
<h5>Dept of Computer Science and engineering</h5></center>";
if(mysql_num_rows($result)==0)
echo "no record found";
else
{
while($array=mysql_fetch_row($result))
{
foreach($array as $f)
print " $f ";
print"<br>";
}
}
print"</body></html>";
mysql_close($mysql);
?>

CSE, CITECH

Page 26

WEB PROGRAMMING LAB MANUAL


OUTPUT:
Hurray inserted successfully!!
Name
sow

Address1
Address2
Bangalore Karnataka

Email-id
sow@gmail.com

14. Using PHP and MySQL, develop a program to accept book information viz. Accession
number, title, authors, edition and publisher from a web page and store the information in
a database and to search for a book with the title specified by the user and to display the
search results with proper headings.
Prg14.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<head>
<title> Mysql </title>
</head>
<body bgcolor="pink" text="yellow" >
<h1> <marquee> Program #14 </marquee> </h1>
<center><h3>XHTML Document to use of PHP & MYSQL</h3>
<h4>City Engineering College</h4>
<h5>Dept. of Computer Science and Engineering</h5> </center>
<hr>
<h1 align="center"> Form to insert values into table </h1>
<form action="prg14a.php">
<table border="1" align="center">
<tr><td> ACCESSION NUMBER:</td>
<td> <input type="text" id="accno" name="accno"/> </td>
</tr>
<tr>
<td> TITLE:</td>
<td> <input type="text" id="tit" name="tit"/> </td>
</tr>
<tr> <td> AUTHOR:</td>
<td> <input type="text" id="aut" name="aut"/> </td>
</tr>
<tr> <td> EDITION:</td>
<td> <input type="text" id="edi" name="edi"/> </td>
</tr>

CSE, CITECH

Page 27

WEB PROGRAMMING LAB MANUAL


<tr> <td> PUBLISHER:</td>
<td> <input type="text" id="pub" name="pub"/> </td>
</tr>
<tr> <td> <input type="submit" value="submit"/> </td>
<td> <input type="reset" value="reset"/> </td>
</tr>
</form>
</table>
<hr/>
<h1 align="center"> Form to retrieve values based on Title </h1>
<form action="prg14b.php">
<table border="1" align="center">
<tr> <td>TITLE:</td>
<td><input type="text" id="title" name="title"/> </td>
</tr>
<tr> <td> <input type="submit" value="submit"/> </td>
<td> <input type="reset" value="reset"/></td>
</tr>
</form>
</table>
</body>
</html>

CSE, CITECH

Page 28

WEB PROGRAMMING LAB MANUAL


Prg14a.php
<?php
$acc=$_GET["accno"];
// Fetch the Fields from the Browser
$title=$_GET["tit"];
$author=$_GET["aut"];
$edition=$_GET["edi"];
$publ=$_GET["pub"];
$mysql=mysql_connect("localhost","root","") or die("cannot connect");
// Connect to DATABASE
$query="insert into bookdetails values('$acc','$title','$author','$edition','$publ')";
mysql_db_query("cec",$query) or die("error in inserting");
//Executing
my Query present in my DB
print "<body bgcolor='grey' text='blue' >
<h1> <marquee> Program #14 </marquee> </h1>
<center><h3>XHTML Document to use of PHP & MYSQL</h3>
<h4>City Engineering College</h4>
<h5>Dept. of Computer Science and Engineering</h5> </center>
<hr><center>Successfully inserted!</center>";
$query="select * from bookdetails";
$result=mysql_db_query("cec",$query) or die("error in selecting");
print "<br/>";
print "<table border=1>";
// fetch the fields n display on Table
while($array=mysql_fetch_row($result))
{
print "<tr>";
foreach($array as $f)
{
print "<td>";
print " $f ";
print "</td>";
}
print "</tr>";
}
print "</table>";
mysql_close($mysql);
?>

CSE, CITECH

Page 29

WEB PROGRAMMING LAB MANUAL


Prg14b.php
<?php
$titl=$_GET['title'];
$mysql=mysql_connect("localhost","root","") or die("cannot connect"); // Connect to
DATABASE
$query="select * from bookdetails where title='$titl'";
$result=mysql_db_query("cec",$query) or die("error in the query");
print "<html> <body bgcolor='red' text='yellow' >
<h1> <marquee> Program #14 </marquee> </h1>
<center><h3>XHTML Document to use of PHP & MYSQL</h3>
<h4>City Engineering College</h4>
<h5>Dept. of Computer Science and Engineering</h5> ";
if(mysql_num_rows($result)==0)
echo "no record found";
else
{
while($array=mysql_fetch_row($result))
{
foreach($array as $f)
print " $f ";
print "<br>";
}
}
print "</body></html>";
mysql_close($mysql);
?>
OUTPUT:

CSE, CITECH

Page 30

Potrebbero piacerti anche