Final Lab Manual WEB
Final Lab Manual WEB
BELGAUM
Complied By:
Trademark
Edition: 2014 - 15
Document Owner
The primary contacts for questions regarding this document are:
Contact email id :
deepak.neo.m@gmail.com
Programming the WEB
Syllabus
1. 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
b) Input: A number n obtained using prompt
Output: A table of numbers from 1 to n and their squares using alert
2. 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)
3. 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.
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.
b) Create an XSLT style sheet for one student element of the above document and use it to create
a display of that element.
5. a) Write a Perl program to display various Server Information like Server Name, Server
Software, Server protocol, CGI Revision etc.
b) Write a Perl program to accept UNIX command from a HTML form and to display the output
of the command executed.
6. a) Write a Perl program to accept the User Name and display a greeting message randomly
chosen from a list of 4 greeting messages.
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.
7. Write a Perl program to display a digital clock which displays the current time of the server.
8. 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.
9. 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.
10. 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.
11. 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.
12. Build a Rails application 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.
Note: In the examination each student picks one question from the
lot of all 12 questions.
Lab Instructions
1. Type the program in notepad and save it with .cgi extension in the C:\wamp\Apache2\cgi-bin
folder.
2. Next type the supported html & save it with .html extension in the same folder.
3. Start server(go to start->programs->Wamp server->start wamp server).
4.open the broser & type the URL as
http://localhost, then it will display the welcome web page
5.Then Open Browser and type the URL as
http://localhost/cgi-bin/pgrogram_name.cgi
EX: http://localhost/cgi-bin/9.cgi
6. Finally output will display.
# cd /var/www/cgi-bin
All perl programs should be saved under.pl extension vim 6a.plpaste the perl program save and
Quit
To see the output go to browser and in the adress bar type
http://localhost/cgi-bin/6a.pl
PROGRAM 1
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.
b) Input: A number ‘n’ obtained using prompt
Output: A table of numbers from 1 to n and their squares using alert.
GUIDELINES:
1) Before doing anything remember please work in root mode(superuser mode)
Screenshot:
Program 1b
<?xml version = "1.0" encoding = "utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<body>
<script type="text/javascript">
var num = prompt("Enter a number : \n", "");
if(num >0 && num !=null)
{
msgstr="Number and its Squares are \n";
for(i=1;i <= num; i++)
{
msgstr = msgstr + i + " -" + i*i + "\n";
}
alert(msgstr)
}
else
alert("No input supplied");
</script>
</body>
</html>
PROGRAM 2
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.
</body>
</html>
Sample Output 1:
Sample Output 2:
PROGRAM 2b
Modify the above program to get the current semester also (restricted to be a number from
1 to 8)
GUIDELINES:
Before doing anything remember please work in root mode(superuser mode)
{
alert("US Number is empty");
elem1.focus();
return false;
}
else if(!elem1.value.match(exp1))
{
alert("Please Enter currect USN number of VTU Format");
elem1.focus();
return false;
}
alert("US Number IS CORRECT");
return true;
}
</script>
</head>
<body>
<form onsubmit='return formValidator()'>
Enter your USN. :
<input type='text' id='req1'/> <br/>
Enter your Sem. :
<input type='text' id='req2'/> <br/>
<input type='submit' value='Check Field' />
</form>
</body>
</html>
Sample Output 1:
Sample Output 2:
PROGRAM 3
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 xmlns="http://www.w3.org/1999/xhtml">
<head>
.layer2Style
{
border: solid thick red;
padding: 1em;
width:300px;
background-color:BLUE;
position:absolute;
top:120px;
left:220px;
z-index:0;
}
.layer3Style
{
border: solid thick green;
padding: 1em;
width:300px;
background-color:purple;
position:absolute;
top:140px;
left:240px;
z-index:0;
}
</style>
<script type="text/javascript">
var topLayer="layer3";
function mover(toTop)
{
var oldTop=document.getElementById(topLayer).style;
var newTop=document.getElementById(toTop).style;
oldTop.zIndex="0";
newTop.zIndex="1";
topLayer=document.getElementById(toTop).id;
}
</script>
</head>
<body>
<h2>Stacking of Paragraphs</h2>
<div style="z-index: 0;" class="layer1Style" id="layer1" onmouseover="mover('layer1')">
Hi!!!!! WEB is Interesting
</div>
Sample Output 1:
PROGRAM 3b
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.
.layer1Style
{
border: solid thick black;
padding: 1em;
width:300px;
background-color:yellow;
position:absolute;
top:200px;
left:400px;
z-index:1;
}
.layer2Style
{
border: solid thick blue;
padding: 1em;
width:300px;
Dept. of CSE, SVIT, Rajanukunte Page 20
Programming the WEB
background-color:red;
position:absolute;
top:220px;
left:420px;
z-index:2;
}
.layer3Style
{
border: solid thick brown;
padding: 1em;
width:300px;
background-color:orange;
position:absolute;
top:240px;
left:440px;
z-index:3;
}
</style>
<script type="text/javascript">
var topLayer="layer3";
var origPos;
function mover(toTop,pos)
{
var newTop=document.getElementById(toTop).style;
newTop.zIndex="10";
topLayer=document.getElementById(toTop).id;
origPos=pos;
}
function moveBack()
{
document.getElementById(topLayer).style.zIndex=origPos;
}
</script>
</head><body>
<br /><br />
<h3>The Stacking of paragraphs,and moved from the top stacking position, it returns to its
original position.</h3>
</body>
</html>
Sample Output:
PROGRAM 4
GUIDELINES:
1) Before doing anything remember please work in root mode(superuser mode)
XML Part:
<details>
<usn>4VA06CS007</usn>
<name>Deepti</name>
<college>SVIT</college>
<branch>Computer Science and Engg</branch>
<year>2010</year>
<email>deepti@gmail.com</email>
</details>
<details>
<usn>1VA06IS047</usn>
<name>Sharath</name>
<college>SVIT</college>
<branch>Information Science and Engg</branch>
<year>2010</year>
<email>sharath@gmail.com</email>
</details>
</vtu_college>
CSS PART:
details{
display:block;
font-size:14pt;
color:red;
font-family:Ariel;
}
usn,name,college,branch,year,email
{
display:block;
font-style:italic;
font-size:16pt;
color:blue;
}
PROGRAM 4b
Create an XSLT style sheet for one student element of the above document and use it to
create a display of that element.
GUIDELINES:
1) Before doing anything remember please work in root mode(superuser mode)
XML Part:
</vtu>
XSL Part:
<!-- 6b.xsl
an XSLT Stylesheet for 6b.xml using implicit templates
-->
<!-- The template for the whole document (the plane element) -->
<xsl:template match = "vtu">
PROGRAM 5
Write a perl program to display various server information like server mail,server
software,server protocol,cgi version etc.
GUIDELINES:
1) Before doing anything remember please work in root mode.
2) Please save the cgi or perl program in /var/www/cgi-bin directory and save the cgi/perl
program as filename.cgi or filename.pl
NOTE: If the file is html then please save in /var/www/html directory
3) Then open the terminal and type cd /var/www/cgi-bin and enter
4) Then give the read-write-execute permission by chmod 777 filename.cgi after you have
written the program then open firefox browser and type http://localhost/cgi-
bin/filename.cgi
NOTE:If you want to access html page then please type http://localhost/filename.html
5) To see the status of the server
service httpd status //displays apache server(daemon process) is running or not
6) If the associated server is not running then start the server else do not start
service httpd start //starts the httpd daemon process
NOTE: Before you write the programs please start the apache server
#! /usr/bin/perl
use CGI ':all';
print
header(),
start_html('more system info'),
h1('server info'),
(
('server name:',server_name()),br(),
('server port:',server_port()),br(),
('server software:',server_software()),br(),
('virtual hosr:',script_name()),br(),
('cgi revision:',$ENV {'GATEWAY_INTERFACE'}),br(),
('serverprotocol:',$ENV {'SERVER_PROTOCOL'})
),
end_html();
HTML PART
<html>
<head>
<title> svit </title>
</head>
<body>
Screenshot:
PROGRAM 5b
Write a perl program to accept unix command from a html form and to display the output
of the command executed.
GUIDELINES:
1) Before doing anything remember please work in root mode.
2) Please save the cgi or perl program in /var/www/cgi-bin directory and save the cgi/perl
program as filename.cgi or filename.pl
NOTE: If the file is html then please save in /var/www/html directory
3) Then open the terminal and type cd /var/www/cgi-bin and enter
4) Then give the read-write-execute permission by chmod 777 filename.cgi after you have
written the program then open firefox browser and type http://localhost/cgi-
bin/filename.cgi
NOTE:If you want to access html page then please type http://localhost/filename.html
5) To see the status of the server
service httpd status //displays apache server(daemon process) is running or not
6) If the associated server is not running then start the server else do not start
service httpd start //starts the httpd daemon process
NOTE: Before you write the programs please start the apache server
#!/usr/bin/perl
use CGI qw(param);
$cmd=param('T1');
print "content-type:text/html\n\n";
print `/usr/bin/$cmd`;
print `/bin/$cmd`;
HTML PART
<html>
<body bgcolor=pink>
<form action="http://localhost/cgi-bin/5b.pl" method=get>
ENTER THE COMMAND:<input type="text" name="T1">
<input type="submit" value="submit">
</form>
</body>
</html>
Screenshot:
PROGRAM 6a
Write a perl program to accept user name and display greeting message randomly chosen
from a list of 4 greeting messages.
GUIDELINES:
1) Before doing anything remember please work in root mode.
2) Please save the cgi or perl program in /var/www/cgi-bin directory and save the cgi/perl
program as filename.cgi or filename.pl
NOTE: If the file is html then please save in /var/www/html directory
3) Then open the terminal and type cd /var/www/cgi-bin and enter
4) Then give the read-write-execute permission by chmod 777 filename.cgi after you have
written the program then open firefox browser and type http://localhost/cgi-
bin/filename.cgi
NOTE:If you want to access html page then please type http://localhost/filename.html
5) To see the status of the server
service httpd status //displays apache server(daemon process) is running or not
6) If the associated server is not running then start the server else do not start
service httpd start //starts the httpd daemon process
NOTE: Before you write the programs please start the apache server
#! /usr/bin/perl
use strict;
use CGI':standard';
my $name=param('yourname');
print header();
print start_html(-title=>'GREETING MESSAGE' -BGCOLOR=>'#1E90FF');
print h2("Hello $name");
my $r=int(rand(4));
if($r==0){
print h2("Hai ".$name);
}
if($r==1){
print h2("Great Day ".$name);
}
if($r==2){
print h2("Welcome ".$name);
}
if($r==3){
print h2("Good Day ".$name);
}
print end_html();
HTML PART
Dept. of CSE, SVIT, Rajanukunte Page 30
Programming the WEB
<html>
<head>
<title>GREETING MESSAGE</title>
</head>
<body bgcolor="#1E90FF">
<form action="http://localhost/cgi-bin/8.pl" method="post">
<br>
Enter your name:<input type="text" name="yourname">
<br>
<br>
<input type="submit" value="click&submit">
<input type="reset" value="click&clear">
</form></body></html>
Screenshot:
PROGRAM 6b
Write a perl program to keep track of number of visitors visiting the webpage and to
display this count of visitor with proper headings.
GUIDELINES:
1) Before doing anything remember please work in root mode.
2) Please save the cgi or perl program in /var/www/cgi-bin directory and save the cgi/perl
program as filename.cgi or filename.pl
NOTE: If the file is html then please save in /var/www/html directory
3) Then open the terminal and type cd /var/www/cgi-bin and enter
4) Then give the read-write-execute permission by chmod 777 filename.cgi after you have
written the program then open firefox browser and type http://localhost/cgi-
bin/filename.cgi
NOTE:If you want to access html page then please type http://localhost/filename.html
5) To see the status of the server
service httpd status //displays apache server(daemon process) is running or not
6) If the associated server is not running then start the server else do not start
service httpd start //starts the httpd daemon process
NOTE: Before you write the programs please start the apache server
#!/usr/bin/perl
print "content-type:text/html","\n\n";
print "<html><body bgcolor=pink>\n";
print "<h2>number of times the page visited is</h2>\n";
my $countfile="r.txt";
my $noaccess;
if(open(FILE,"<".$countfile))
{
$noaccess=<FILE>;
close(FILE);
if(open(FILE,">".$countfile))
{
$noaccess++;
print FILE $noaccess;
close(FILE);
}
}
print $noaccess;
print "</body></html>"
HTML PART
<html>
<body>
<form action="http://localhost/cgi-bin/8b.pl" method=get>
<input type="submit" value="submit">
</form>
</body>
</html>
Screenshot:
PROGRAM 7
Write a perl program to display a digital clock which displays the current time of the
server.
GUIDELINES:
1) Before doing anything remember please work in root mode.
2) Please save the cgi or perl program in /var/www/cgi-bin directory and save the cgi/perl
program as filename.cgi or filename.pl
NOTE: If the file is html then please save in /var/www/html directory
3) Then open the terminal and type cd /var/www/cgi-bin and enter
4) Then give the read-write-execute permission by chmod 777 filename.cgi after you have
written the program then open firefox browser and type http://localhost/cgi-
bin/filename.cgi
NOTE:If you want to access html page then please type http://localhost/filename.html
5) To see the status of the server
service httpd status //displays apache server(daemon process) is running or not
6) If the associated server is not running then start the server else do not start
service httpd start //starts the httpd daemon process
NOTE: Before you write the programs please start the apache server
#!/usr/bin/perl
use strict;
use CGI':all';
my($time,$str);
my($sec,$min,$hr)=localtime(time);
if($hr>=12)
{
$hr=$hr-12;
$str="pm";
}
else
{
$str="am";
}
$time=sprintf("%02d:%02d:%02d%s",$hr,$min,$sec,$str);
print "content-type:text/html","\n\n";
print "<body bgcolor=pink>";
print "<meta http-equiv=refresh content=1>";
print "$time";
HTML PART
<html>
<body>
<form action="http://localhost/cgi-bin/9.pl" method=get>
<input type="submit" value="submit">
</form>
</body>
</html>
Screenshot:
PROGRAM 8
Write a perl program to insert name and age information entered by the user into a
table,created using mysql and display the current contents in the table.
GUIDELINES:
1) Before doing anything remember please work in root mode.
2) Please save the cgi or perl program in /var/www/cgi-bin directory and save the cgi/perl
program as filename.cgi or filename.pl
NOTE: If the file is html then please save in /var/www/html directory
3) Then open the terminal and type cd /var/www/cgi-bin and enter
4) Then give the read-write-execute permission by chmod 777 filename.cgi after you have
written the program then open firefox browser and type http://localhost/cgi-
bin/filename.cgi
NOTE:If you want to access html page then please type http://localhost/filename.html
5) To see the status of the server
service httpd status //displays apache server(daemon process) is running or not
6) If the associated server is not running then start the server else do not start
service httpd start //starts the httpd daemon process
NOTE: Before you write the programs please start the apache server
7) To work in mysql environment please type the command:
mysql –u root // here root is username and password is null
8) After typing the above command you will enter the mysql working environment then
follow the following instruction below
show databases; //it will display the all available databases
9) If you want to create a database then type
For eg: create SVIT;
10) Then make use of the created database to create table and query the tables under the
database just created. Type the command Ans:
use SVIT; //makes use of the database you just created.
11) To create the tables
create table student(
firstname varchar(25);
lastname varchar(20);
age int
);
12) Insert the rows into the tables Ans: for eg:
insert into student values(“prakash”,”r”,22);
13) To see the values in the table then type for eg:
select<column name>from<tablename>;
#!/usr/bin/perl
print "content-type:text/html","\n\n";
use DBI;
use CGI;
$form=new CGI;
$name=$form->param('name');
$age=$form->param('age');
$dbh=DBI->connect("DBI:mysql:svit","root","");
$insertrow=$dbh->prepare("insert into student3 values('$name','$age')");
$insertrow->execute();
$insertrow->finish();
$query=$dbh->prepare("select * from student3");
$query->execute();
$nrow=$query->rows;
print "<pre>";
print "<h1>name\t age\t </h1>";
for($i=1;$i<=$nrow;$i++)
{
@emparray=$query->fetchrow_array;
print "$emparray[0]\t\t";
print "$emparray[1]";
print "<pre>";
}
HTML PART
<html>
<body>
<form action="http://localhost/cgi-bin/10.pl" method=get>
name<input type="text" name="name">
age<input type="text" name="age">
<input type="submit" value="submit">
</form>
</body>
</html>
Screenshot:
PROGRAM 09
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.
GUIDELINES:
1) Before doing anything remember please work in root mode.
2) Please goto directory /var/www/html and create new directory as php and give the root
permission for the php directory as chmod 777 php and please save the php program in
/var/www/html/php directory and save the php program as filename.php
NOTE: If the file is html then please save in /var/www/html directory
3) Then open the terminal and type cd /var/www/html /php and enter
4) Then give the read-write-execute permission by chmod 777 filename.php after you have
written the program then open firefox browser and type
http://localhost/php/filename.php
NOTE:If you want to access html page then please type http://localhost/filename.html
5) To see the status of the server
service httpd status //displays apache server(daemon process) is running or not
6) If the associated server is not running then start the server else do not start
service httpd start //starts the httpd daemon process
NOTE: Before you write the programs please start the apache server
PHP Part:
<?php
$Month = 2592000 + time();
//this adds 30 days to the current time
setcookie(‘AboutVisit’, date("F jS - g:i a"), $Month);
?>
<?php
if(isset($_COOKIE['AboutVisit']))
{
$last = $_COOKIE['AboutVisit'];
echo "Welcome back! <br> You last visited on ". $last;
}
else
{
echo "Welcome to our site!";
}
?>
Screenshot:
PROGRAM 10
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.
GUIDELINES:
1) Before doing anything remember please work in root mode.
2) Please goto directory /var/www/html and create new directory as php and give the root
permission for the php directory as chmod 777 php and please save the php program in
/var/www/html/php directory and save the php program as filename.php
NOTE: If the file is html then please save in /var/www/html directory
3) Then open the terminal and type cd /var/www/html /php and enter
4) Then give the read-write-execute permission by chmod 777 filename.php after you have
written the program then open firefox browser and type
http://localhost/php/filename.php
NOTE:If you want to access html page then please type http://localhost/filename.html
5) To see the status of the server
service httpd status //displays apache server(daemon process) is running or not
6) If the associated server is not running then start the server else do not start
service httpd start //starts the httpd daemon process
NOTE: Before you write the programs please start the apache server
PHP PART:
<?php
session_start();
session_register("count");
if(!isset($_SESSION))
{
$_SESSION["count"]=0;
echo"<p>counter initialized</p>\n";
}
echo $_SESSION["count"]++;
echo "<p>the counter is now<b>$_SESSION[count]</b></p>";
echo "<p>reload this page to increment</p>";
?>
Screenshot:
PROGRAM 11
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.
GUIDELINES:
1) Before doing anything remember please work in root mode.
2) Please save the cgi or perl program in /var/www/cgi-bin directory and save the cgi/perl
program as filename.cgi or filename.pl
NOTE: If the file is html then please save in /var/www/html directory
3) Then open the terminal and type cd /var/www/cgi-bin and enter
4) Then give the read-write-execute permission by chmod 777 filename.cgi after you have
written the program then open firefox browser and type http://localhost/cgi-
bin/filename.cgi
NOTE:If you want to access html page then please type http://localhost/filename.html
5) To see the status of the server
service httpd status //displays apache server(daemon process) is running or not
6) If the associated server is not running then start the server else do not start
service httpd start //starts the httpd daemon process
NOTE: Before you write the programs please start the apache server
7) To work in mysql environment please type the command:
mysql –u root // here root is username and password is null
8) After typing the above command you will enter the mysql working environment then
follow the following instruction below
show databases; //it will display the all available databases
9) If you want to create a database then type
For eg: create SVIT;
10) Then make use of the created database to create table and query the tables under the
database just created. Type the command Ans:
use SVIT; //makes use of the database you just created.
11) To create the tables
create table student(
firstname varchar(25);
lastname varchar(20);
age int
);
12) Insert the rows into the tables Ans: for eg:
insert into student values(“prakash”,”r”,22);
13) To see the values in the table then type for eg:
select<column name>from<tablename>;
INSERTION:
PHP PART:
<?php
$name=$_POST["name"];
$ad1=$_POST["ad1"];
$ad2=$_POST["ad2"];
$email=$_POST["email"];
$result=1;
$mysql=mysql_connect("localhost","root","") or die("connect err");
mysql_select_db("svit");
$result=mysql_query("insert into person values('$name','$ad1','$ad2','$email')");
print "name= $name ad1 = $ad1 ad2= $ad2 mail = $email result= $result " ;
?>
<html>
<head>
<title> Query DB </title>
</head>
<body>
<center> <h3><? if($result==1) print "Record Inserted Successfully"; ?></h3></center>
<h4>Current DB contents</h4>
<? $result=mysql_query("select * from person"); ?>
<table border="1" align="center" width="500">
<tr>
<th>Name</th><th>ad1</th><th>Ad2</th><th>Email</th></tr>
<? while($array=mysql_fetch_row($result)) {
print "<tr>";
print "<td>". $array[0]." </td>";
print "<td>". $array[1]." </td>";
print "<td>". $array[2]." </td>";
print "<td>". $array[3]." </td>";
print "</tr>";
}
mysql_free_result($result);
mysql_close($mysql);
?>
</table>
</body>
</html>
HTML PART:
<html>
<head>
<title> Personal Details </title>
</head>
<body bgcolor="grey">
<form action="http://localhost/php/13a.php" method="post">
Complete the form below and click "Submit" <br>
<table width="500">
<tr>
<td>Name </td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Address1 </td>
<td><input type="text" name="ad1"></td>
</tr>
<tr>
<td>Address2 </td>
<td><input type="text" name="ad2"></td>
</tr>
<tr>
<td>Email ID </td>
<td><input type="text" name="email"></td>
</tr>
<tr><td><div align="center"><input type="submit"></td></tr>
</table>
</form>
</body>
</html>
Screenshot:
SEARCHING:
PHP PART:
<?
$name=$_POST["name"];
$found=0;
$mysql=mysql_connect("localhost","root","")or die("connect error");
mysql_select_db("svit");
$result=mysql_query("select *from person where name = '".$name. "'");
if(mysql_num_rows($result)>=1) $found=1;
?>
<html>
<body>
<h1>
<?
if($found==1) print "person found";
else print "not found";?>
</h1>
<table border="1" align="center" width="500">
<tr>
<th>name</th>
<th>Ad1</th>
<th>Ad2</th>
<th>e-mail</th>
</tr>
<? while($array=mysql_fetch_row($result)){
print"<tr>";
print "<td>".$array[0]."</td>";
print "<td>".$array[1]."</td>";
print "<td>".$array[2]."</td>";
print "<td>".$array[3]."</td>";
print "</tr>";
}
mysql_free_result($result);
mysql_close($mysql);
?>
</table>
</body>
</html>
HTML PART:
<head>
<title>search</title>
</head>
<body bgcolor="grey">
Screenshot:
Program No 12
Build a rails application to accept book 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
Step 1:
Step 2: .
Say(C:\myrails\InstantRails-2.0-win\instantrails) As in my case
Step 3:
Copy the directory named rails_apps into the directory named ruby (Because rails run on
ruby)
Note: InstantRails-2.0-win.zip is a self contained system, it doesn’t require any installation. Just
extracting the files is enough.
Step 4:
Goto “C:\myrails\InstantRails-2.0-win\instantrails” .You can see the rails icon “I” in red
color. As shown in the snapshot below. Double click on it.
Step 5:
A rails application will be invoked. You can manage the servers by this application.
Snapshot is given below.
Step 6:
Click on the icon on the top left corner, goto Rails application->open ruby console window
as shown in the example below.
Lab Program 12
Create a database:
>mysql –u root
> exit
Follow Step 4 to Step 6 and you can see the following window
“C:\myrails\InstantRails-2.0-win\instantrails\ruby\rails_apps”
<body>
<p> Total number of books = <%= @num_books %> </p>
<form action = "result" >
Enter Searching Element: <input type="text" name="sid" />
<input type=submit value="Search" />
</form>
</body>
</html>
Starting Rails Server
ruby script/server
Executing in the web browser
http://localhost:3000/main/welcome
Ans: three types of lists are available <ul> for unordered list, <ol> for ordered list, <dl> for definition
lists.