Wednesday, November 24, 2010

1.      Develop and demonstrate a XHTML document that illustrates the use external style sheet, ordered list, table, borders, padding, color, and the <span> tag.

// Store this code in the HTML folder and save it as mystyle.css.

p,table,li,                                                                                            
{
font-family: "lucida calligraphy", arial, 'sans serif';
margin-left: 10pt;
}

p { word-spacing: 5px; }

body { background-color:rgb(200,255,205); }                           

p,li,td { font-size: 75%;}

td { padding: 0.5cm; }

th {
      text-align:center;
      font-size: 85%;
    }
           
h1, h2, h3, hr {color:#483d8b;}

table
{
border-style: outset;
background-color: rgb(100,255,105);
}

li {list-style-type: lower-roman;}
span
{
color:blue;
background-color:pink;
font-size: 29pt;
font-style: italic;
font-weight: bold;
}

//Store this code in the HTML folder and save it as lab1.html . Call this program in the browser by going to file options open FILE.

 <?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">
<head>                                                                                   
<link rel="stylesheet" type="text/css" href="mystyle.css" />
<title> Lab program1 </title>
</head>
<body>
   <h1>This header is 36 pt</h1> 
   <h2>This header is blue</h2>
   <p>This paragraph has a left margin of 50 pixels</p>

<table border="4" >    <!-- table with name & email -->
  <tr>
            <th >Name </th>
            <th>Email</th>
  </tr>
  <tr>
            <td >Ramu</td>
            <td>ramu@gmail.com</td>
  </tr>
  <tr>
            <td >Seetha</td>
            <td>seetha@rediffmail.com</td>
  </tr>
  <tr>
            <td >Lakshman</td>
            <td>lak@gmail.com</td>
  </tr>
  <tr>
            <td >Krishna</td>
            <td>krishna@hotmail.com</td>
  </tr>
</table>
<hr>        <!-- horizontal line -->
<ol> <!-- ordered list -->
  <li> TSB Singh</li>
  <li> Prakash S </li>
  <li> ManojKumar</li>
</ol>

<p>
<span>This is a text.</span> This is a text. This is a text. This is a text. <span>This is a text.</span>
</p>
</body>
</html>




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

//Type this program in the html folder and save it as 2a.html. Call this program in the browser by going to file options open FILE.

<?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 fib1=0,fib2=1,fib=0;
var num = prompt("Enter a number : \n", "");

if(num!=null && num>0)
{
 document.write("<h1>" + num + " Fibonocci are <br></h1>");
 if(num==1)
    document.write("<h1> "+ fib1 + "<br /></h1>");
 else
    document.write("<h1>" + fib1 + "<br /> " + fib2 + "</h1>");

 for(i=3;i<=num; i++)
 {
  fib= fib1 + fib2;
  document.write("<h1> " + fib + "<br /></h1>");
  fib1=fib2;
  fib2=fib;
 }
}
else
 alert("No Proper Input");
</script>
</body>
</html>

2b) Input: A number n obtained using prompt
      Output: A table of numbers from 1 to n and their squares using alert

//Type this program in the html folder and save it as 2b.html. Call this program in the browser by going to file options open FILE.

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






3a) Develop and demonstrate a XHTML file that includes Javascript script that uses functions for the following problems:
a)      Parameter: A string       
b)     Output: The position in the string of the left-most vowel

//Type this program in the html folder and save it as 3a.html. Call this program in the browser by going to file options open FILE.

<? 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">
            <head>
              <title> string.html </title>
             <script type="text/javascript">
       function str_vowel()
        {
          var str= prompt("Enter the string\n", " ");
          for( var i=0; i<str.length; 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(" The entered string is:" +str+ "<br/>");
                               document.write(" The leftmost vowel is:" +str.charAt(i)+
                                       "<br/>");
                   var pos=i+1;
                   document.write(" The position of the leftmost vowel "   
                                  +str.charAt(i)+ " is: " +pos+ "<br />");
                   exit;
                }
}
         document.write(" The entered string is:" +str+ "<br/>");
               document.write(" The entered string has no vowels ");
       }
  </script>
</head>
  <body  style="background-color:yellow" onload="str_vowel();" >
     <h3 style="text-align:center;color:red"> Program includes Javascript     
        script functions to find the position of the left-most vowel in the
                               entered  string.</h3>
  </body>

</html>


 3b) Parameter: A number
    Output: The number with its digits in the reverse order.

//Type this program in the html folder and save it as 3b.html. Call this program in the browser by going to file options open FILE.

<? 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">
          <head>
       <title> reverse.html </title>
<script type="text/javascript">
                function rev_num()
                         {
                           var num = prompt("Enter the number to be reversed:"," ");
                            var n = num;
                           var rev = 0,rem;
                           while(n > 0)
                                       {
                                                rem = n % 10;
                                                rev = rev * 10 + rem;
                                                n = Math.floor( n / 10);
                                       }
                            document.write("The given number is  : " +num+ " <br /> The                           reverse of the given number is :" +rev+ "<br />");
                          }
         </script>
    </head>
    <body style="background-color:yellow" onload="rev_num();">
        <h3 style="text-align:center;color:red"> Program includes Javascript
                    script functions to reverse the entered number.</h3>
    </body>
</html>            
4 4a)  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.

//Type this program in the html folder and save it as 4a.html. Call this program in the browser by going to file options open FILE.

<?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/">
<head><title>USN.html</title>
  <script type="text/javascript">
       function checkusn()
       {
         var str=document.getElementById("usn");
         var result=str.value.search(/^[1-4]{1}[A-Z]{2}\d{2}[A-Z]{2}\d{3}$/);
          if(result!=0)
           {
            alert("Entered usn("+str.value+") is not in the correct form.\n"+
               "The correct pattern is : 1AY05IS001\n"+"Please go back and
                       retype your USN");              
          }
        else
          {
           alert("Entered usn("+str.value+") is in the correct form.\n");
          }
      }
 </script>
</head>
 <body style="background-color:yellow">
  <h3 style="text-align:center;color:red"> Program includes XHTML document to Collect the Student-Information</h3>
            <h3 style="color:purple">Student Information </h3>
            <form name="my form">
          <p style="color:purple"> Enter your USN:</p>
          <input type="text" id="usn" size=15/>
          <br/>
          <br/>
         <input type="button" onclick="checkusn()" value="Submit"/>
         <input type = "reset" value= "Reset" />
          <br/>
      </form>
  </body>
</html>                    
4.b) Modify the above program to get the current semester also (restricted to be a number from 1 to 8)

//Type this program in the html folder and save it as 4b.html. Call this program in the browser by going to file options open FILE.


<?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/">
<head><title>USN.html</title>
  <script type="text/javascript">
       function checkusnsem()
       {
         var str=document.getElementById("usn");
         var result=str.value.search(/^[1-4]{1}[a-zA-Z]{2}\d{2}[a-zA-Z]{2}\d{3}$/);
           
            var str12=document.getElementById (“sem”);
            var result12=str12.value.search(/^[1-8]{1}$/);
      
   if(result!=0 && result12!=0)
           {
            alert("Entered usn("+str.value+") is not in the correct form.\n"+
               "The correct pattern is : 1AY05IS001\n"+"Please go back and
                       retype your USN\n"+”Entered Sem(“+str12.value+”) is not in the 1-8 range”);
            }
            else if(result!=0 && result12==0)       
             {
            alert (“Entered USN(“+str.value+”) is not correct\n”+but sem(“+str12.value+”) is in the correct range”);
}

else if( result==0 && result12!=0)
{
alert (“Entered USN(“+str.value+”) is  correct\n”+but sem(“+str12.value+”) is not in the correct range”);
}
else
          {
 alert("Entered usn("+str.value+")  and Entered Sem(“+str12.value+”)are in the correct form.\n");
          }
      }
 </script>
</head>
 <body style="background-color:yellow">
  <h3 style="text-align:center;color:red"> Program includes XHTML document to Collect the Student-Information</h3>
            <h3 style="color:purple">Student Information </h3>
            <form name="my form">
          <p style="color:purple"> Enter your USN:</p>
          <input type="text" id="usn" size=15/>
            <input type=”text” id=”sem” size=”3” />
          <br/>
          <br/>
         <input type="button" onclick="checkusnsem()" value="Submit"/>
         <input type = "reset" value= "Reset" />
          <br/>
      </form>
  </body>
</html>                      
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.

//Type this program in the html folder and save it as 5a.html. Call this program in the browser by going to file options open FILE.

<?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/">
 <head>
      <title>The Stacking order</title>
           <style type="text/css">
              .layer1Style
                  {
   border: solid thick black;
               padding: 1em;
               width: 300px;
               background-color: green;
               position: absolute;
               top:100px;
               left: 200px;
   z-index: 0;
  }
 .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="10";
topLayer=document.getElementById(toTop).id;
    }
  </script>
    </head>
     <body><body style="background-color: yellow">
       <h2 style="text-align: center; color: red"> Program includes XHTML       document to show the Stacking of Paragraphs</h2>
        <div style="z-index:10;" class="layer1Style" id="layer1"  onmouseover="mover('layer1')">
            Welcome to Acharya Institute of Technology. This college offers courses like Information Science and Engineering, Computer science and Engineering , Electronic Communication and Engineering , Electrical Engineering , Mechanical Engineering and Bio-technology.
       </div>
       <div style="z-index: 2;" class="layer2Style" id="layer2" 
         onmouseover="mover('layer2')">
           The college also offers courses like MBA and MCA.
      </div>
      <div style="z-index: 0;" class="layer3Style" id="layer3" onmouseover="mover('layer3')">
          The college has an excellent infrastructure, beautiful building, a Huge playground and also hostel facilities.
       </div>

   
</body>
</html>


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

//Type this program in the html folder and save it as 5b.html. Call this program in the browser by going to file options open FILE.

<?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/">
  <title>The Stacking order</title>
       <style type="text/css">
        .layer1Style{
                                             border: solid thick black;
padding: 1em;
width:300px;
background-color:green;
position:absolute;
top:100px;
left:400px;
z-index:1;
}
.layer2Style{
border: solid thick blue;
padding: 1em;
width:300px;
background-color:red;
position:absolute;
top:120px;
left:420px;
z-index:2;
}
.layer3Style{
border: solid thick brown;
padding: 1em;
width:300px;
background-color:orange;
position:absolute;
top:140px;
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 style="background-color:yellow">
   <h1 style="text-align:center;color:red"> The Stacking of paragraphs when  moved from the top stacking position, it returns to its original position.</h1>
  <div style="z-index: 1;" class="layer1Style" id="layer1"   onmouseover="mover('layer1','1')" onmouseout="moveBack()">
The lives of most inhabitants of Industrailzed Countries, has well as some unindustralized countries, have been changed forever by the advent of WWW.
 </div>
   <div style="z-index:2;" class="layer2Style" id="layer2" onmouseover="mover('layer2','2')" onmouseout="moveBack()">
The www may seem like magic , untill you undrestand how it works.The Web is  accessed  through a browser.
</div>
  <div style="z-index: 3;" class="layer3Style" id="layer3" onmouseover="mover('layer3','3')" onmouseout="moveBack()">
Lunix  provides many ways for you to communicate with friends, co-workers, and  with  the rest of the world.
   </div>
 </body>
</html>
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.

//Type this program in the html folder and save it as 6a.xml. Call this program in the browser by going to file options open FILE.

<?xml version = "1.0"?>                                                                    
<?xml-stylesheet type = "text/css" href = "6a.css" ?>
<students>

<h1> Student Information </h1>

<h3>Student 1</h3>
   <VTU>
      <label>USN: <usn> 1AY08CS001 </usn></label>
      <label>NAME: <name> Amar </name></label>
      <label>COLLEGE: <college> ACIT </college></label>
      <label>BRANCH: <branch> CSE</branch></label>
      <label>YEAR of JOINING:<YOJ> 2008 </YOJ></label>
      <label>EMAIL: <email> amar@gmail.com </email></label>
   </VTU>

<h3>Student 2</h3>
   <VTU>
      <label>USN : <usn> 1AY08CS002</usn></label>
      <label>NAME: <name> asha</name></label>
      <label>COLLGE: <college> ACIT </college></label>
      <label>BRANCH: <branch> CSE </branch></label>
      <label>YEAR of JOINING: <YOJ> 2008 </YOJ></label>
      <label>EMAIL : <email> asha@acharya.ac.in </email></label>
   </VTU>

<h3>Student 3</h3>
   <VTU>
      <label>USN : <usn> 1AY08CS003 </usn></label>
      <label>NAME <name> Bhavya </name></label>
      <label>COLLEGE: <college> ACIT</college></label>
      <label>BRANCH: <branch> CSE </branch></label>
      <label>YEAR of JOINING: <YOJ> 2008</YOJ></label>
      <label>EMAIL: <email> bhavya@yahoo.com </email></label>
   </VTU>

</students>


//Type this program in the html folder and save it as 6a.css. (External style sheet for 6a.xml)

label {display:block; margin-left:15px; color:blue; font-size:13pt;}
usn {color:red; font-size:12pt; margin-left: 15px;}
name {color:red; font-size:12pt; margin-left: 15px;}
college {color:red; font-size:12pt; margin-left: 15px;}
branch {color:red; font-size:12pt; margin-left: 15px;}
year {color:red; font-size:12pt; margin-left: 15px;}
email {color:red; font-size:12pt; margin-left: 15px;}
h1 {color:red;font-size:18pt;}
h3 {display:block;color:black;font-size:16pt:}


   (Explanation : display: can have two options inline and block .”block” means after printing that line it will display the cursor on the next line. If inline means the cursor will be blinking on the same line)     

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.


//Type this program in the html folder and save it as 6b.xml.  Assign 777 permissions to this program and call this program in the browser by going to URL bar and typing it as http://localhost/6b.xml

<?xml version = "1.0"?>                                                        
<?xml-stylesheet type = "text/xsl"  href = "6b.xsl" ?>

<VTU>
   <USN> 1AY08CS001 </USN>
   <name> Amar </name>
   <college> ACIT</college>
   <branch> CSE </branch>
   <YOJ> 2007 </YOJ>
   <email> amar@gmail.com </email>
</VTU>


//Type this program in the html folder and save it as 6b.xsl.  Assign 777 permissions to this program

<?xml version = "1.0"?>
<xsl:stylesheet version = "1.0"
             xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
             xmlns = "http://www.w3.org/1999/xhtml">

<xsl:output method=”html” />
<xsl:template match = "VTU">

 <html><head><title> Style sheet for 6b.xml </title>
 </head>
<body bgcolor=”red”>
 <h2> VTU Student Description </h2>

 <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;"> Year of Join:  </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>

(Explanation:
For Template match we have to give the root element (here VTU)
When value-of select is used it should be same as the tag what is given in the xml file because xml is case sensitive
)
7 a) Write a Perl program to display various Server Information like Server Name, Server Software, Server protocol, CGI Revision etc.

//Type this program in the cgi-bin folder and save it as 7a.cgi (program can either be saved as 7a.cgi or 7a.pl).  Assign 777 permissions to this program and call this program in the browser by going to URL bar and typing it as http://localhost/cgi-bin/7a.cgi

To know the syntax errors go to command prompt and type “perl 7a.cgi”

#!/usr/bin/perl                                                             
use CGI':standard';                                                                
print "content-type: text/html","\n\n";
print "<html>\n";
print "<head> <title> About this server </title> </head>\n";
print "<body><h1> About this server </h1>","\n";
print "<hr>";
print "Server name :",$ENV{'SERVER_NAME'},"<br>";
print "Running on port :",$ENV{'SERVER_PORT'},"<br>";
print "Server Software :",$ENV{'SERVER_SOFTWARE'},"<br>";
print "CGI-Revision :",$ENV{'GATEWAY_INTERFACE'},"<br>";
print "<hr>\n";
print "</body></html>\n";
exit(0);

   7 b) Write a Perl program to accept UNIX command from a HTML form and to display the output of the command executed.

//Type this program in the html folder and save it as 7b.html.  Call this program in the browser by going to the file options open FILE.

<html>                                                                                               
<body>
<form action=”http://localhost/cgi-bin/7b.cgi method=”POST”>
<input type="text" name="com">
<input type="submit" value="Submit">
</form>
</html>

//Type this program in the cgi-bin folder and save it as 7b.cgi.  Assign 777 permissions to this program.

#!/usr/bin/perl
use CGI':standard';                                                                                        
print "content-type: text/html “,”\n\n";
$c=param('com');
system($c);
exit(0);
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.

//Type this program in the html folder and save it as 8a.html.  Call this program in the browser by going to the file options open FILE.

<html>
    <head>
          <title> NAME</title>
    </head>
    <body bgcolor=”yellow”>
         <form action="http://localhost/cgi-bin/8a.cgi" method="get">
             Name:<input type ="text" name="name"><br/><hr/>
             <input type="submit" value="click to submit">
   <input type="reset" value="click to reset">
         </form>
     </body>
</html>

//Type this  program in the /var/www/cgi-bin folder and save it as 8a.cgi
#!/usr/bin/perl
use strict;
use CGI qw/:standard/;           (or use CGI’:standard’; because qw is quote word)
print “content-type:text/html”,”\n\n”;
my $name =param('name');
print “<html><body> bgcolor=aabbcc>”;
print “<h3> Hi, $name</h3>”;
my @msgs=(“Good”,”Welcome”, “Fine”,”Hello”);
print “<h3> The message received is : “;
print $msgs[int rand scalar @msgs];
print “</h3></body></html>”;
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.


//Type this program in the cgi-bin folder and save it as 8b.cgi. Create a file called count.txt in the same folder, insert 0 into that and assign 777 permissions to count.txt.  Assign 777 permissions to 8b.cgi program and call 8b.cgi program in the browser by going to the URL bar and typing it as http://localhost/cgi-bin/8b.cgi.

#!/usr/bin/perl
use CGI ':standard';
use CGI::Carp qw(warningsToBrowser);
print “content-type:text/html”,”\n\n”;

print “<html><head><title>Web page counter</title></head>”;
print “<body bgcolor=”pink”>”;
print “<font color=”blue”>”;

open(FILE,'<count.txt');
$count=<FILE>;
close(FILE);

$count++;
open(FILE,'>count.txt');
print FILE "$count";

print b("This page has been viewed $count times");
close(FILE);
print “</body></html>”;



9. Write a Perl program to display a digital clock which displays the current time of the server.

//Save this program in the CGI-BIN folder as 9.cgi. Assign  777 permissions to this program and call this program in the browser as http://localhost/cgi-bin/9.cgi

#!/usr/bin/perl

use CGI ':standard';
print "Refresh: 1\n";
print "content-type: text/html”,”\n\n";

print “<html><head><title>Program 8</title> </head>”;
print “<body bgcolor=”black”>”;
print “<font color=”white”>;

($s,$m,$h)=localtime(time);

print br,br,"The current system time is $h:$m:$s";
print br,br,hr,"In words $h hours $m minutes $s seconds";
print end_html;


(Explanation: Refresh:1 is nothing but the time has to be refreshed every 1 second.

            br,br,hr is similar to using <br /> <br /> <hr />
            end_html is similar to using </html>
     )

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.

//Store this code in the HTML folder and save it as 10.html. This program is for inserting name and age fields into the mysql database. Call this html program in the browser by going to file options open file.

<html>
<body>
<form action=”http://localhost/cgi-bin/10.cgi  method=”GET” >
  Name : <input type="text" name="name"> <br>
  Age :<input type="text" name="age"> <br>
<input type="submit" value="Submit">
</form>
</html>


//Before typing this program go to mysql and create a table called stud with name and age columns and insert some values in this table.
//Store this code in the CGI-BIN  folder and save it as 10.cgi. Assign 777 permissions to this program.This program is for fetching the results from html program and storing it in the mysql database.

#! /usr/bin/perl
print "content-type: text/html”,”\n\n";
print "<html><title>Result of the insert operation </title>";
use CGI ':standard';
use DBI;
$dbh=DBI->connect("DBI:mysql:test","student","student");
$name=param("name");
$age=param("age");
$qh=$dbh->prepare("insert into stud values('$name','$age')");
$qh->execute();
$qh=$dbh->prepare("select * from stud");
$qh->execute();
print "<table border size=1><tr><th>Name</th><th>Age</th></tr>";

while ( ($name,$age)=$qh->fetchrow())
{
       print "<tr><td>$name</td><td>$age</td></tr>";
}

print "</table>";
$qh->finish();
$dbh->disconnect();
print "</html>";


(Explanation: DBI-> connect("DBI:mysql:test","student","student");
    test  is the name of the database
    student is the user name for the mysql.
    student (3rd parameter) is the password for the mysql

Entering mysql: (all statements in mysql should end with semicolon)

1)      mysql –u root –p
it will ask for password, then type root. Mysql prompt will appear
2)      mysql> create database student;
             It will create a database with name student
3)      mysql> grant all on student.* to student@localhost  identified by ‘student’;
             It will assign all permissions to student database with username “student” and password “student”
4)      mysql>show databases;
It will display all the databases available in the system.
5)      mysql> use test ;
we are telling that we are using the test database.
6)      show tables;
It will display all the available tables in the test database.
7)      create table stud(name varchar(20), age int);
8)      insert into stud values(‘abc’,20);



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.

// Store this code in the HTM/PHP folder and save it as 11.php. Assign 777 permissions to this program. Call this program in the browser as http://localhost/php/11.php

<?php

//Calculate 60 days in the future
//seconds * minutes * hours * days + current time

$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 "You've got some stale cookies!";
?>

(Explanation:
date("G:i - m/d/y"): It will call the date function . 1st parameter is G:i means G is 24 hour format and I is 60 minutes format
m/d/y means month, date and year
$_COOKIE is the built-in array for storing the cookies parameter is the name of the cookie
)

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.

// Store this code in the HTM/PHP folder and save it as 12.php. Assign 777 permissions to this program. Call this program in the browser as http://localhost/php/12.php

<?php
session_start();
session_register("count");

if (!isset($_SESSION[“count”])) 
{
    $_SESSION["count"] = 0;
    echo "<p>Counter initialized</p>\n";
} 
else { $_SESSION["count"]++; }

echo "<p>The counter is now <b>$_SESSION[count]</b></p>".
    "<p>reload this page to increment</p>";
?>


 

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>
   <body bgcolor="aabbcc">
     <h3> Program to accept the Book-Information</h3>
         <form action = "http://localhost/php/13a.php" method = "post">
                                                 
Enter NAME:   <input type = "text" name = "name" size=”10”>
                        Enter ADDRESS1: <input type = "text" name = "address1” size=”10”>                              
                        Enter ADDRESS2: <input type = "text" name = "address2" size=”10”>
Enter EMAIL: <input type = "text" name = "email" size=”10”>
                       
                                     <input type = "submit" value = "submit">
                                      <input type = "reset" value = "Reset">
</form>
           </body>
           </html>

Store this code in the HTML/PHP folder and save it as 13a.php . Assign 777 permissions to this program(To insert  the details of the book entered by the user into the mysql table)
<?       
$name=$_POST["name"];
$add1=$_POST["address1"];
$add2=$_POST["address2"];
$email=$_POST["email"];
$mysql=mysql_connect ("localhost","student",”student”) or die ("can't connect");
mysql_select_db ("address") or die ("can't select");
mysql_query ("insert into add_info values ('$name','$add1','$add2','$email')") or die("query failed to insert");
$result=mysql_query("select * from add_info"); 
?>
<html>
<head><title>PHP and MYSQL</title></head>
 <body bgcolor="aabbcc">
   <table border="1">
<tr>
<th>NAME</th>
<th>ADDRESS1</th>
<th>ADDRESS2</th>
<th>EMAIL</th>
</tr>
         <?while($array=mysql_fetch_row($result)):?>
             <tr>
                                    <td><?echo $array[0];?></td>
                                    <td><?echo $array[1];?></td>
                                    <td><?echo $array[2];?></td>
                                    <td><?echo $array[3];?></td>
            </tr>
  <? endwhile;?>
       <?mysql_free_result($result);?>
     <?mysql_close($mysql);?>
   </table>
  </body>
</html>
//Store this code in the HTML folder and save it as 13b.html. This program is for searching for one particular name from the database

<html>   
<head><title>Program 13b</title></head>
<body>
   <form action="http://localhost/php/13b.php" method="POST">
      Enter Name of the person <input type="text" name="name">
      <input type=”submit” value=”SUBMIT QUERY>
   </form>
</body>
</html>

Store this code in the HTML/PHP folder and save it as 13b.php . Assign 777 permissions to this program(To insert  the details of the book entered by the user into the mysql table)

<?
    $name = $_POST["name"];
    $mysql = mysql_connect("localhost","student",”student”)or die("Cannot Connect");
     mysql_select_db("address") or die("Cannot select the database");
    $result =mysql_query("select * from add_info where title like  '%$name%' ") or die  ("cannot execute");
?>
<html>
   <body bgcolor="aabbcc">
       <? if(mysql_num_rows($result)>0): ?>
          <table border = "1">
                   <tr>
                                                <th>NAME</th>
                                                <th>ADDRESS1</th>
                                                 <th>ADDRESS2</th>
                                                <th>EMAIL</th>
                                                        </tr>
            <b>Query Executed for Search</b>
            <? while($array = mysql_fetch_row($result)):?>
                                <tr>
                                    <td><?echo $array[0];?></td>
                                    <td><?echo $array[1];?></td>
                                    <td><?echo $array[2];?></td>
                                    <td><?echo $array[3];?></td>
                               </tr>
      <? endwhile;?>
     <? else: ?>              <?echo "no rows selected";?>
     <? endif;?>
    </table>    </body>
</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 the search results with proper headings
// Save this program as 14a.html in the HTML folder(To enter the details of the books by the user).
//Open the above HTML program in the browser by going to file options open file
<html>
   <body bgcolor="aabbcc">
     <h3> Program to accept the Book-Information</h3>
         <form action = "http://localhost/php/14a.php" method = "post">
                                                 
Enter ISBN:   <input type = "text" name = "isbn" size=”10”>
                        Enter TITLE: <input type = "text" name = "title" size=”10”>                                    
                        Enter AUTHOR: <input type = "text" name = "author" size=”10”>
Enter EDITION: <input type = "text" name = "edition" size=”10”>
                        Enter PUBLICATION:  <input type = "text" name = "publication" size=”10”>
                                     <input type = "submit" value = "submit">
                                      <input type = "reset" value = "Reset">
</form>
           </body>
           </html>

Store this code in the HTML/PHP folder and save it as 14a.php . Assign 777 permissions to this program(To insert  the details of the book entered by the user into the mysql table)
<?       
$isbn=$_POST["isbn"];
$title=$_POST["title"];
$author=$_POST["author"];
$edition=$_POST["edition"];
$publication=$_POST["publication"];
$mysql=mysql_connect ("localhost","student",”student”) or die ("can't connect");
mysql_select_db ("test") or die ("can't select");
mysql_query ("insert into book_info values ('$isbn','$title','$author','$edition','$publication')") or die("query failed to insert");
$result=mysql_query("select * from book_info"); 
?>
<html>
<head><title>PHP and MYSQL</title></head>
 <body bgcolor="aabbcc">
   <table border="1">
<tr>
<th>ISBN</th>
<th>TITLE</th>
<th>AUTHOR</th>
<th>EDITION</th>
<th>PUBLICATION</th>
</tr>
         <?while($array=mysql_fetch_row($result)):?>
             <tr>
                                    <td><?echo $array[0];?></td>
                                    <td><?echo $array[1];?></td>
                                    <td><?echo $array[2];?></td>
                                    <td><?echo $array[3];?></td>
                                    <td><?echo $array[4];?></td>
</tr>
  <? endwhile;?>
       <?mysql_free_result($result);?>
     <?mysql_close($mysql);?>
   </table>
  </body>
</html>

//Save this program as 14b.html in the HTML folder(to make the search based on the title of given by user).
//Open the 14b  HTML program in the browser by going to FILE options open file.
<html>
   <body bgcolor="aabbcc">
     <h3>Search Page</h3>
        <form action = "http://localhost/php/14b.php" method = "post">
            Enter the title of the book to be searched:
             <input type = "text" name = "search">
             <br/>
             <input type = "submit" value = "submit">
             <input type = "reset" value = "Reset">   <br/>
         </form>
    </body>
</html>

Save this code as 14b.php in the HTMl/php folder and 777 permissions to this program
(To search for the book with the title specified by the user)
<?
    $search = $_POST["search"];
    $mysql = mysql_connect("localhost","student",”student”)or die("Cannot Connect");
     mysql_select_db("books") or die("Cannot select the database");
    $result =mysql_query("select * from book_info where title like  '%$search%' ") or die  ("cannot execute");
?>
<html>
   <body bgcolor="aabbcc">
       <? if(mysql_num_rows($result)>0): ?>
          <table border = "1">
                   <tr>
                                                <th>ISBN</th>
                                                <th>Title</th>
                                                 <th>Author</th>
                                                <th>Edition</th>
                                    <th>Publication</th>
                    </tr>
            <b>Query Executed for Search</b>
            <? while($array = mysql_fetch_row($result)):?>
                                <tr>
                                    <td><?echo $array[0];?></td>
                                    <td><?echo $array[1];?></td>
                                    <td><?echo $array[2];?></td>
                                    <td><?echo $array[3];?></td>
                                    <td><?echo $array[4];?></td>
                                      </tr>
      <? endwhile;?>
     
<? else: ?>       <?echo "no rows selected";?>
     <? endif;?>
    </table>    </body>
</html>