Académique Documents
Professionnel Documents
Culture Documents
1.Develop and demonstrate a XHTML document that illustrates the use of external style
sheet, ordered list, table, borders, padding, color, and the <span> tag.
<html>
<head>MCA<title>EvenSemester</title></head>
<body>
<style>
.sahana
{
font-size:25;
border-bottom-style:dashed;
}
</style>
<CENTER><font color="blue" class=sahana>Rao Bahadur Y.Mahabaleshwarappa Engineering
College</font>
<h4>Department of Master of Computer Application</h4>
<h5>Time-Table for Even Semester 2008-2009</h5>
<h6 align="left">Sem:IV</h6></CENTER></head>
<table border=10>
<tr>
<th width="8%">Day</th>
<th>8:00-9:00AM</th>
<th>9:00-10:00AM</th>
<th width="20%" rowspan=4>10:00-
10:30AM<br>B</br><br>R</br><br>E</br>A</br><br>K</br></th>
<th>10:30-11:30AM</th>
<th>11:30-12:30PM</th>
<th width="20%" rowspan=6>12:30-2:00PM
<br>L</br><br>U</br><br>N</br><br>C</br><br>H</br></th>
<th>2:00-3:00PM</th>
<th>3:00-4:00PM</th>
<th>4:00-5:00PM</th>
</tr>
<tr align="center">
<td>Mon</td>
<td><a href="g.html#WP">WP</a></td>
<td><a href="g.html#EA-1">EA-1</a></td>
<td><a href="g.html#SE">SE</a></td>
<td><a href="g.html#ADA">ADA</a></td>
<td><a href="g.html#USP">USP</a></td>
<td colspan=2>ADA(B3)</td>
</tr>
<tr align="center">
<td>Tue</td>
<td><a href="g.html#SE">SE</a></td>
<td><a href="g.html#ADA">ADA</a></td>
<td><a href="g.html#EA-1">EA-1</a></td>
<td>-</td>
<td><a href="g.html#USP">USP</a></td>
<td colspan=2>WP(B3)</td>
</tr>
<tr align="center">
<td>Wed</td>
<td><a href="g.html#ADA">ADA</a></td>
<td><a href="g.html#USP">USP</a></td>
<td><a href="g.html#EA-1">EA-1</a></td>
<td>-</td>
<td><a href="g.html#SE">SE</a></td>
<td><a href="g.html#WP">WP</a></td>
<td>-</td>
</tr>
<tr align="center">
<td>Thur</td>
<td colspan=4>ADA(B3)(Upto 11:00)</td>
<td><a href="g.html#WP">WP</a></td>
<td><a href="g.html#EA-1">EA-1</a></td>
<td colspan=2>JAVA(B3)</td>
</tr>
<tr align="center">
<td>Fri</td><td>
<a href="g.html#USP">USP</a></td>
<td><a href="g.html#SE">SE</a></td>
<td>BREAK</td>
<td><a href="g.html#WP">WP</a></td>
<td><a href="g.html#ADA">ADA</a></td>
<td colspan=3>JAVA(B3)</td></tr>
<tr align="center"><td>Sat</td><td colspan=5>WP(B3)(Upto 11:00)</td>
</tr>
</table>
<table border=2 width="100%">
<tr>
<td>EA-1 Shivanand.K.B</td>
<td>SE A.T.Satyanarayana Reddy</td>
</tr>
<tr>
<td>WP T.Heera Singh</td>
<td>ADA E.N.V Rajesh</td>
</tr>
<tr>
<td>USP T.Hanumantha Reddy</td>
<td>JavaLaboratory Shivanand.K.B</td>
</tr>
<tr>
<td>WebProgrammingLaboratory T.Heera Singh</td>
<td>ADALaboratory E.N.V.Rajesh</td>
</tr>
</table>
</body></html>
<html>
<head>
<title>Syllabus Page</title>
</head>
<body>
<a href="timetable.html">back to timetable</a>
<p id="EA-1"><h1>EA-1</h1>
<ol type="1">
<li>Introduction to Java
<li>Classes,Inheritance,Exceptions,Applets
<li>Multi Threaded Programming,Event Handling
<li>Swings
<li>Java 2 Enterprise Edition Overview,Database Access
<li>Servlets
<li>JSP,RMI
<li>Enterprise Java Beans
</ol>
<a href="timetable.html">back to timetable</a>
<p id="SE"><h1>SE</h1>
<ol type="1">
<li>Overview
<li>Critical Systems,Software Processes
<li>REquirements
<li>System models,Project Management
<li>Software Design
<li>Development
<li>Verification and Validation
<li>Management
</ol>
<a href="timetable.html">back to timetable</a>
<p id="WP"><h1>WP</h1>
<ol type="1">
<li>Fundamentals of web,XHTML-1
<li>XHTML-2,CSS
<li>JavaScript
Output for g.html XHTML document: It links to particular subject when clicked on that
particular subject in timetable.
WP
1. Fundamentals of web,XHTML-1
2. XHTML-2,CSS
3. JavaScript
4. JavaScript and HTML Documents,Dynamic Documents with JavaScript
5. XML
6. Perl,CGI Programming
7. PHP
8. Database Access
back to timetable
2. Develop and demonstrate a XHTML file that includes Javascript for the following
problems
a) Input: A number n obtained using prompt
Output: The first n Fibonacci numbers
<html>
<head>
<title>Fibonacci series</title>
</head>
<body>
<script language="Javascript">
var f1=0,f2=1,f3,i;
var n=prompt("Enter the limit"," ");
document.writeln("fibonacci series","</br>",f1,"</br>",f2,"</br>");
for(i=2;i<n;i++)
{
f3=f1+f2;
document.write(f3+"</br>");
f1=f2;
f2=f3;
}
</script>
</body>
</html>
Output:
Output:
3. Develop & demonstrate a XHTML file that includes javascript that uses functions for
the following problems:
a) Parameter: A String
Output: The position in the string of the left-most vowel
<html>
<head>
<title>Left-most vowel</title>
<script language="javascript">
function vowel()
{
var str=document.myform.result.value;
var c,i;
for(i=0;i<str.length;i++)
{
c=str.charAt(i);
if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='A' || c=='E' || c=='I' || c=='O' || c=='U')
{
return(i+1);
}}
return -1;
}
function display()
{
var i=vowel();
if(i==-1)
document.myform.mytext.value="vowel not found";
else
document.myform.mytext.value="vowel found at"+i;
}
</script>
</head>
<body>
<form name="myform">
<input type="text" name="result" value=" ">
<input type="text" name="mytext"value=" "readonly>
<input type="button" name="btn" value="find leftmost vowel" onclick="display()">
</form>
</body>
</html>
Output:
Dept of MCA, RYMEC, Bellary. 2008-2009 Page 12
Web Programming Laboratory 07MCA47
<html>
<head>
<title>Reverse of a given number</title>
</head>
<body>
<script language="javascript">
function reverse(num)
{
var rev=0,n1=num,rem;
while(num>0)
{
rem=parseInt(num%10);
rev=parseInt(rev*10+rem);
num=parseInt(num/10);
}
document.write("Numbers are=",n1,"</br>");
document.write("Reverse numbers=",rev);
}
var num=prompt("Enter number to find reverse number","");
reverse(num);
</script>
</body>
</html>
Output:
4.a) Develop and demonstrate, using Javascript , a XHTML document that collects
Dept of MCA, RYMEC, Bellary. 2008-2009 Page 15
Web Programming Laboratory 07MCA47
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.
//usn.js
function chkName()
{
var myName=document.getElementById("USNName");
var str="20";
var d=new Date();
var temp=new RegExp("^[1-4]{1}[A-Z]{2}[\\d]{2}[A-Z]{2}[\\d]{3}$");
var t=temp.test(myName.value);
if(t==false)
{
alert("USN entered is wrong");
}
Else
{
Output:
4.b). Modify the above program to get the current semester also.
var mon=d.getMonth();
str=cur-str;
str*=2;
if(mon<6)
str=str;
else
str+=1;
if(str<=8)
alert("current semester:"+str);
else
alert("Semester Beyonds 8 sem");
myName.focus();
myName.select();
}}
Output:
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.
<html>
<head>
<title>New Document</title>
<script language="javascript">
function fun1()
{
document.getElementById("first").style.visibility="visible";
var second=document.getElementById("second");
second.style.top=100;
var third=document.getElementById("third");
}
function fun2()
{
document.getElementById("first").style.visibility="visible";
var second=document.getElementById("second");
var third=document.getElementById("third");
}
function fun3()
{
document.getElementById("seconda").style.visibility="visible";
var second=document.getElementById("third");
third.style.top=160;
}
function fun4()
{
document.getElementById("seconda").style.visibility="visible";
var third=document.getElementById("third");
}
function fun5()
{
document.getElementById("thirda").style.visibility="visible";
}
function fun6()
{
document.getElementById("thirda").style.visibility="visible";
}
</script>
</head>
<body>
<span style="position:absolute;top:40;left:25" onmouseover="fun1()" onmouseout="fun2()">
Output:
5.b)Modify the above document so that when a paragraph is moved from the top
Dept of MCA, RYMEC, Bellary. 2008-2009 Page 24
Web Programming Laboratory 07MCA47
Stacking position, it returns to its original position rather than to the bottom.
<html>
<head>
<title>New Document</title>
<script language="javascript">
function fun1()
{
document.getElementById("first").style.visibility="visible";
var second=document.getElementById("second");
second.style.top=150;
var third=document.getElementById("third");
third.style.top=180;
}
function fun2()
{
document.getElementById("first").style.visibility="hidden";
var second=document.getElementById("second");
second.style.top=70;
var third=document.getElementById("third");
third.style.top=90;
}
function fun3()
{
document.getElementById("seconda").style.visibility="visible";
var second=document.getElementById("third");
third.style.top=180;
}
function fun4()
{
document.getElementById("seconda").style.visibility="hidden";
var third=document.getElementById("third");
third.style.top=90;
}
function fun5()
{
document.getElementById("thirda").style.visibility="visible";
}
function fun6()
{
document.getElementById("thirda").style.visibility="hidden";
}
</script>
</head>
<body>
<span style="position:absolute;top:40;left:25" onmouseover="fun1()" onmouseout="fun2()">
place mouse here to view first paragraph</span><br>
<span id="first" style="position:absolute;top:60;left:25;
visibility:hidden;">
If file sharing is prohibited in your country,dont download it</span>
<span id="second" style="position:absolute;top:80;left:25;" onmouseover="fun3()"
onmouseout="fun4()">
place mouse here to view second paragraph</span><br>
<span id="seconda" style="position:absolute;top:100;left:25; visibility:hidden">
This activity is just for Test/Backup purpose only</span>
<span id="third" style="position:absolute;top:140;left:25;" onmouseover="fun5()"
onmouseout="fun6()">
Place mouse here to view third paragraph</span><br>
<span id="thirda" style="position:absolute;top:160;left:25; visibility:hidden">
This activity is just for test/backup pupose only</span>
</body>
</html>
Output:
//xml document
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<?xml-stylesheet type="text/css" href="6a.css"?>
<STUDENT>
<DETAILS>
<TITLE>STUDENT INFORMATION</TITLE>
</DETAILS>
<DETAILS>
<USN><a>USN:</a>3VC07MCA36</USN>
<NAME><a>NAME:</a>SAHANA</NAME>
<COLLEGE><a>COLLEGE:</a>R.Y.M.E.C</COLLEGE>
<BRANCH><a>BRANCH:</a>MCA</BRANCH>
<YEAROFJOINING><a>Year of Joining:</a>2007</YEAROFJOINING>
<EMAIL-ID><a>Email-id:</a>sahana.20@rediffmail.com</EMAIL-ID>
</DETAILS>
<DETAILS>
<USN><a>USN:</a>3VC07MCA40</USN>
<NAME><a>NAME:</a>SWETHA</NAME>
<COLLEGE><a>COLLEGE:</a>R.Y.M.E.C</COLLEGE>
<BRANCH><a>BRANCH:</a>MCA</BRANCH>
<YEAROFJOINING><a>Year of Joining:</a>2007</YEAROFJOINING>
<EMAIL-ID><a>Email-id:</a>swetha_avanthika@gmail.com</EMAIL-ID>
</DETAILS>
<DETAILS>
<USN><a>USN:</a>3VC07MCA43</USN>
<NAME><a>NAME:</a>VARNIKA</NAME>
<COLLEGE><a>COLLEGE:</a>R.Y.M.E.C</COLLEGE>
<BRANCH><a>BRANCH:</a>MCA</BRANCH>
<YEAROFJOINING><a>Year of Joining:</a>2007</YEAROFJOINING>
<EMAIL-ID><a>Email-id:</a>varnikadesai@gmail.com</EMAIL-ID>
</DETAILS>
</STUDENT>
//6a.css document
STUDENT
{
}
DETAILS
{
display:block;
color:"black";
font-size:20pt;
font-family:"Times New Roman";
font-weight:bold;
border-style:solid;
}
TITLE
{
color:"yellow";
font-size:20pt;
font-family:"Times New Roman";
text-decoration:underline;
text-indent:1.5in;
}
a
{
text-align:"left";
color:"black";
font-size:18pt;
font-family:"Times New Roman";
}
USN
{
display:block;
color:"black";
font-size:18pt;
font-family:"Times New Roman";
}
NAME
{
display:block;
color:"black";
font-size:18pt;
Dept of MCA, RYMEC, Bellary. 2008-2009 Page 29
Web Programming Laboratory 07MCA47
Output:
b) Create an XSLT style sheet for one student element of the above document and use it
//xml document
<?xml-stylesheet type="text/xsl" href="6b.xsl"?>
<STUDENT>
<details>
<USN>3VC07MCA43</USN>
<NAME>Varnika</NAME>
<COLLEGE>R.Y.M.E.C</COLLEGE>
<BRANCH>MCA</BRANCH>
<YEAR>2007</YEAR>
<EMAIL-ID>varnikadesai@gmail.com</EMAIL-ID>
</details>
</STUDENT>
//xsl document
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/XHTML">
<xsl:template match="STUDENT">
<html>
<head>
<title>xsl document</title>
</head>
<body>
<h2>
<center>STUDENT INFORMATION</center></FONT>
</h2>
<table border="3" allign="center">
<tr>
<th>
<span style="font-style:italic;font-size:25;">USN:</span>
</th>
<th>
<span style="font-style:italic;font-size:25;">NAME:</span>
</th>
<th>
<span style="font-style:italic;font-size:25;">COLLEGE:</span>
</th>
<th>
<span style="font-style:italic;font-size:25;">BRANCH:</span>
</th>
<th>
<span style="font-style:italic;font-size:25;">YEAR OF JOINING:</span>
</th>
<th>
<span style="font-style:italic;font-size:25;">EMAIL-ID:</span>
</th>
</tr>
<xsl:for-each select="details">
<tr>
<td>
<xsl:value-of select="USN"/>
</td>
<td>
<xsl:value-of select="NAME"/>
</td>
<td>
<xsl:value-of select="COLLEGE"/>
</td>
<td>
<xsl:value-of select="BRANCH"/>
</td>
<td>
<xsl:value-of select="YEAR"/>
</td>
<td>
<xsl:value-of select="EMAIL-ID"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output:
7. a) Write a Perl program to display various Server Information like Server Name, Server
#!/perl/bin/perl.exe
use CGI;
$cgi=new CGI;
print $cgi->header;
print $cgi->start_html('Program 1a');
print $cgi->h1('Server Informations');
print $cgi->hr;
print "<table border=4 cellpadding=2>";
print "<tr><td>SERVER_NAME: </td><td>", $ENV{'SERVER_NAME'}, "</td></tr>";
print "<tr><td>SERVER_PROTOCOL: </td><td>", $ENV{'SERVER_PROTOCOL'},
"</td></tr>";
print "<tr><td>SERVER_SOFTWARE: </td><td>", $ENV{'SERVER_SOFTWARE'},
"</td></tr>";
print "<tr><td>GATEWAY_INTERFACE:</td><td>", $ENV{'GATEWAY_INTERFACE'},
"</td></tr>";
print "</table>";
print $cgi->end_html;
OUTPUT:
Start>Run>http://localhost/cgi-bin/prog1a.cgi
7.b. Write a Perl program to accept UNIX command from a HTML form and to display
the output of the command executed.
#!/perl/bin/perl.exe
use CGI;
$cgi=new CGI;
print $cgi->header;
print $cgi->start_html('Program 1b');
print $cgi->h1('Unix Command Executor');
print $cgi->hr;
print $cgi->h3('Please enter the unix command');
print $cgi->start_form( -method=>'post', -action=>'/cgi-bin/prog1b.cgi');
print "Unix Command:";
print $cgi->textfield( -name=>'command',-value=>'');
print $cgi->submit( -name=>'submit',-value=>'Execute');
print $cgi->endform;
print $cgi->hr;
$command=$cgi->param("command");
if($command ne "")
{
print " The output of the unix command: $command";
$output=`$command`;
print "<pre>";
print $output;
print "</pre>";
}
print $cgi->hr;
print $cgi->end_html;
OUTPUT:
Start>Run>http://localhost/cgi-bin/prog1a.cgi
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.
#!/perl/bin/perl.exe
use CGI;
$cgi=new CGI;
print $cgi->header;
print $cgi->start_html('Program 2a');
print $cgi->h1('Greeting a User');
print $cgi->hr;
print $cgi->h3('Dear User <br> Enter the username');
print $cgi->start_form( -method=>'post',-action=>'/cgi-bin/greet.cgi');
print "User Name:";
print $cgi->textfield( -name=>'username',-value=>'');
print $cgi->submit( -name=>'submit',-value=>'Process');
print $cgi->reset ;
print $cgi->endform;
print $cgi->hr;
print $cgi->end_html;
#!/perl/bin/perl.exe
use CGI;
$cgi=new CGI;
print $cgi->header;
print $cgi->start_html('Program 3');
print $cgi->h1('<center>Welcome</center>');
print "$username";
print $cgi->hr;
($sec,$min,$hour)=localtime(time);
if($hour> 23 || $hour< 6)
{
$greet="u r 2 early";
}
elsif($hour>= 6 && $hour< 12)
{
$greet="a very gud mrg 2 u";
}
elsif($hour>= 12 && $hour< 18)
{
$greet="gud afternoon 2 u";
}
else
{
$greet="gud nite";
}
$time=sprintf("%02d:%02d:%02d",$hour,$min,$sec);
print"<font size=5+ color=blue><center>the time is</font><font size=10+ color=red> $time
<h2><i>$greet</i></h2>";
OUTPUT:
Start>Run>http://localhost/cgi-bin/prg8.cgi
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.
#!/perl/bin/perl.exe
use CGI;
$cgi=new CGI;
print $cgi->header;
print $cgi->start_html('Program 8b');
print $cgi->h1('<center>Server Page Visited Informations</center>');
print $cgi->hr;
$count_file="c:/count.txt";
if(open(FILE,"<".$count_file)) {
$no_accesses=<FILE>;
close(FILE);
if(open (FILE,">".$count_file)) {
$no_accesses++;
print FILE $no_accesses;
close(FILE);
}
else {
print "Cannot write the file. No Visitors information in the server";
} } else {
print "cannot read the counter database for visitors";
}
print "Welcome User";
print "<BR><BR>This page has been accessed <font color=red size=10> $no_accesses </font>
times from the creation";
print $cgi->end_html;
OUTPUT:
Start>Run>http://localhost/cgi-bin/8b.cgi
9. Write a Perl program to display a digital clock which displays the current time of the
server.
#!c:/perl/bin/perl.exe
use CGI;
$cgi=new CGI;
print $cgi->header;
print $cgi->start_html('Program 9');
print $cgi->h1('<center>Server Time on Digital Clock');
print $cgi->hr;
($seconds,$minutes,$hour)=localtime(time);
if($hour>12) {
$hour-=12;
$ampm='PM';
}
else
{
$ampm='AM';
}
if($hour==0)
{
$hour=12;
}
$time=sprintf("%02d:%02d:%02d %s",$hour,$minutes,$seconds,$ampm);
print "User: the Time is<br><br>";
print $time."</center>";
print $cgi->hr;
print $cgi->end_html;
OUTPUT:
Start>Run>http://localhost/cgi-bin/prog9.cgi
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.
#!c:/perl/bin/perl.exe
#
# 6. Program to insert new name and age into the database.
#
use Win32::ODBC;
use CGI;
$cgi=new CGI;
print $cgi->header;
print $cgi->start_html('Program 6');
print $cgi->h1('<center>Database Insertion Operation</center>');
print $cgi->hr;
$database=new Win32::ODBC("myown");
$table="myown";
print "<center>Enter the information below to save.<br><br>";
$query="select max(userid) from $table";
$database->Sql($query);
@fieldnames=$database->FieldNames();
print "<form method=post action=/cgi-bin/prog6save.cgi>";
print $cgi->table({-border=>0,-cellpadding=>10,-cellspacing=>0});
print $cgi->caption('<b><i>User Information</i></b>');
if($database->FetchRow())
{
%data=$database->DataHash();
print $cgi->Tr({-valign=>top,-align=>center});
print $cgi->td('Userid');
print "<input type=hidden name=userid value=".++$data{'max(userid)'}.">";
print $cgi->td('<input type=text name=userid value='.$data{'max(userid)'}.'
disabled>');
}
print $cgi->Tr({-valign=>top,-align=>center});
print $cgi->td('Name:');
print $cgi->td('<input type=text name=name1>');
print $cgi->Tr({-valign=>top,-align=>center});
print $cgi->td('Age:');
print $cgi->td('<input type=text name=age>');
print $cgi->Tr({-valign=>top,-align=>center});
print $cgi->td;
print $cgi->td('<input type=submit value=Submit> <input type=reset
value=Clear>');
print "</table>";
print "</form></center>";
print $cgi->end_html;
#!c:/perl/bin/perl.exe
# prog6save.cgi - 2nd part
#Program to get and insert new name and age information into the database.
#
use CGI;
use Win32::ODBC;
$cgi=new CGI;
print $cgi->header;
print $cgi->start_html('2nd part of program 6');
print $cgi->h1('<center>Database Save Information');
print $cgi->hr;
$userid=$cgi->param('userid');
$name=$cgi->param('name1');
$age=$cgi->param('age');
$database=new Win32::ODBC("myown");
$query="insert into myown values(\'$name\',$age)";
$database->Sql($query);
print "Dear user $name:<br><br>";
print "Your information has been saved";
print "<br><br><a href=/cgi-bin/prog6.cgi>Back</a></center>";
print $cgi->hr;
print $cgi->end_html;
Database changed
OUTPUT:
1.Start>control panel>administrative toos> Data Sources (ODBC)>
2.select system DSN tab>add>click
3.Select MySQL server 5.1 Driver
4. Data Source Name:myown
5.Server:localhost
6.User:varnika
7.password:varnika
8.data base:library
9:click ok,ok,ok.
Start>run> http://localhost/cgi-bin/prog6.cgi
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.
<?
// get current date information as associative array
if(isset($_COOKIE['Datee']))
{
$cookiedate = $_COOKIE['Datee'];
}
$todayh = getdate();
$d = $todayh[mday];
$m = $todayh[mon];
$y = $todayh[year];
$hr = $todayh[hours];
$mi = $todayh[minutes];
$se = $todayh[seconds];
$datestring ="$d-$m-$y, $hr:$mi:$se";
setcookie("Datee",$datestring);
print "Program for creating and displaying cookie";
print"<br>";
echo "<br>Hello, ".$cookiedate."! last visited!";
print"<br>";
?>
Run
Start>run> http://localhost/prg11.php
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.
<?php
session_start();
if(isset($_SESSION['count'])){
print "Your session count: ".$_SESSION['count']. "<br>";
$_SESSION['count']++;
} else {
$_SESSION['count'] = 1;
print "Session does not exist";
}
?>
Output:-
Run
Start>run> http://localhost/prg12.php
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.
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY bgcolor=cyan>
<form method="get" action="php13.php"><br><FONT COLOR="orange">
<h1><center>BOOK INFORMATION</h1>
<table align=center><tr><td>Enter Name</td>
<td><input type="text" name="name"></td></tr>
<tr><td>enter address1</td><input type="text" name="add1"></td></tr>
<tr><td>enter address2</td><input type="text" name="add2"></td></tr>
<tr><td>enter email</td><input type="text" name="email"></td></tr>
</table><br><br>
<center><input type="reset" value="CLEAR"><br><br>
<center><input type="submit" value="INSERT">
</form>
</BODY>
</HTML>
Save: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php13.html
<html>
<head>
<title> name and address database with MySQL </title>
</head>
<body>
<?php
// Connect to MySQL
$add2 = $_GET['add2'];
$email = $_GET['email'];
$sname=$_GET[‘sname’];
$c = "insert into contact (name,add1,add2,email) values ('" . $name . "','" . $add1 . "','" . $add2 .
"','" . $email . "')";
$er = mysql_select_db("emp");
if (!$er) {
print "Error - Could not select the EMP database" . mysql_error();
exit;
}
$a = mysql_query( $c );
$res = mysql_query("select * from contact where name = '$sname'");
$count = mysql_num_rows($res);
$col = mysql_num_fields($res);
//print "Totoal Cols present in Book Table " . $col . "<br>";
print "<table border=1>";
$i=0;
while($i < $col)
{
print "<td>" . $row[$i];
$i = $i +1;
}
}
?>
</body>
</html>
Output:-
Create a table in Mysql with name person and with attributes in the program.
Insert rows as shown below.
Run
Start>run> http://localhost/php13.html
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
<html>
<head>
<title> Access the library database with MySQL </title>
</head>
<body>
<?php
// Connect to MySQL
$db = mysql_connect("localhost", "varnika", "varnika");
if (!$db) {
print "Error - Could not connect to MySQL";
exit;
}
$acn = $_GET['acn'];
$tit = $_GET['tit'];
$aut = $_GET['aut'];
$edi = $_GET['edi'];
$pub = $_GET['pub'];
$c = "insert into book (acn,tit,aut,edi,pub) values (" . $acn . ",'" . $tit . "','" . $aut . "','" . $edi .
"','" . $pub . "')";
// Select the library database
$er = mysql_select_db("library");
if (!$er) {
print "Error - Could not select the library database" . mysql_error();
exit;
}
$a = mysql_query( $c );
$res = mysql_query("select * from book");
$count = mysql_num_rows($res);
$col = mysql_num_fields($res);
print"<form action=pgm14.html><input type=submit value=BACK>";
print"<h1>Book Information</h1>";
print "<table border=1>";
while ( $row = mysql_fetch_array($res))
{
print "<tr>";
$i=0;
while($i < $col)
{
print "<td>" . $row[$i];
$i = $i +1;
}
}
?>
</body>
</html>
Save: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\pgm14.php
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<form method="get" action="pgm14.php"><br>
<h1><center>BOOK INFORMATION</h1>
<table align=center>
<tr><th>Enter acession number</th><td><input type="text" name="acn"></td></tr>
<tr><th>enter title</th><td><input type="text" name="tit"></td></tr>
<tr><th>enter author name</th><td><input type="text" name="aut"></td></tr>
<tr><th>enter edition </th><td><input type="text" name="edi"></td></tr>
<tr><th>enter publication</th><td><input type="text" name="pub"></td></tr>
</table><br><br>
<center><input type="reset" value="CLEAR"><br><br>
<center><input type="submit" value="INSERT">
</form>
</BODY>
</HTML>