Sunteți pe pagina 1din 59

Web Programming Lab.

PROGRAM #1

<!--Develop and demonstrate an XHTML document that illustrates the use of external style sheet, ordered list, table, borders, padding, color and the <span> tag -->
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD/XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml10/DTD/xhtml10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> Popcorn </title> <link href="mystyle.css" rel="stylesheet" type="text/css" /> </head> <body> <p class="para" align="center"> Welcome to <span class="spanblue"> MGBC </span> Popcorn Sales </p> <table border="1" cellpadding="10" bgcolor="pink" align="center"> <thead> <tr> <th> Product Name </th> <th> Price </th> </tr> </thead> <tbody> <tr> <td> Unpoped Popcorn </td> <td> $3.00 </td> </tr> <tr> <td> Caramel P.C </td> <td> $3.50 </td> </tr> <tr> <td> Caramel Nut P.C <ol> <li> Type1 </li> <li> Type2 </li> </ol> </td> <td> <br/> $4.50 <br/> $3:50 </td> </tr> Department of CSE Page 1

Web Programming Lab.

<tr> <td> Toffy Nut P.C </td> <td> $5.00 </td> </tr> </tbody> </table> </body> </html>

//-------------------mystyle.css---------------------.para{font-size:25pt ;color:green;} .spanblue{font-size:35pt ;color:blue;}

Department of CSE

Page 2

Web Programming Lab.

OUTPUT:

Department of CSE

Page 3

Web Programming Lab.

PROGRAM #2

<!--Develop and demonstrate a XHTML file that includes JavaScript for the following problems: (a)Input: A no. n obtained using prompt. Output: The first n fibonacci numbers. (b)Input: A no. n obtained using prompt Output: A table of numbers from 1 to n and their squares using alert.-- >
<?xml version="1.0" encoding=utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD/XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml10/DTD/xhtml10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript"> function fibonacci() { var n=prompt("Enter a number"," "); if(isNaN(n)) alert("Invalid number. Enter a right one"); else if(n ==n.match(/[0-9]*/)) { var a=0; var b=1; if(n==0) document.write("No such series"); document.write("FIBONACCI SERIES:<br/>"); if(n==1) document.write(a+"<br/>"); else { document.write(a+"<br/>"); for(var i=2;i<=n;i++) { var c=a+b; a=b; b=c; document.write(c+"<br/>"); } } } else alert("Series not valid"); } Department of CSE Page 4

Web Programming Lab.

function square() { var n=prompt("Enter a number"," "); if(isNaN(n)) alert("Invalid number enter a right one"); else if(n==0) document.write("Not an integer"); else if(n ==n.match(/[0-9]*/)) { var str="The numbers and its squares\n "; for(i=1;i<=n;i++) str=str+i+"--"+i*i+"\n"; alert(str); } else document.write("Not allowed"); } </script> </head> <body> <h3><center>WEBPAGE TO OUTPUT N FIBONACCI OR SQUARE OF N NUMBERS </center> </h3> <table border="6" align="center"> <tbody align="center"> <tr> <td><input type="radio" name="a" onclick ="fibonacci()"/></td> <td>FIBONACCI</td> </tr> <tr> <td><input type="radio" name="a" onclick ="square()"/></td> <td>SQUARE</td> </tr> </tbody> </table> </body> </html>

Department of CSE

Page 5

Web Programming Lab.

OUTPUT:

Department of CSE

Page 6

Web Programming Lab.

Department of CSE

Page 7

Web Programming Lab.

Department of CSE

Page 8

Web Programming Lab.

PROGRAM #3

<!--Develop and demonstrate an XHTML file that includes JavaScript which uses functions for the following problems: (a)Parameter : A string Output : Position in the string of the leftmost vowel. (b)Parameter : A number Output : The number with its digits in reverse order.-->
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD/XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml10/DTD/xhtml10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript"> function vowels(str) { var c=""; for(i=0;i<str.length;i++) { if(str.charAt(i)==str.match(/[aeiouAEIOU]/)) { c=str.charAt(i); i++ break; } } alert("The left most vowel is "+c+" at position "+i); } function reverse(n) { var rev=0,rem=0; if(n!=n.match(/[0-9]*/)) alert("Invalid entry. Enter a whole number"); else { var n=Number(n); while(n!=0) { rem=n%10; Department of CSE Page 9

Web Programming Lab.

n=Math.floor(n/10); rev=rev*10+rem; } alert("The reversed number is "+rev); } } </script> </head> <body> <center> <h3>WEB PAGE TO REVERSE A NUMBER OR FIND THE LEFTMOST VOWEL OF THE STRING</h3> </center> <table border="6" align="center"> <tbody align="center"> <tr> <td>Enter the string</td> <td><input type="text" id="txtstr"/></td> <td><input type="button" value="Go" onclick="vowels(txtstr.value)"/><br/></td> </tr> <tr> <td>Enter the number</td> <td><input type="text" id="num"/></td> <td><input type="button" value="Go" onclick="reverse(num.value)"/></td> </tr> </tbody> </table> </body> </html>

Department of CSE

Page 10

Web Programming Lab.

OUTPUT:

Department of CSE

Page 11

Web Programming Lab.

Department of CSE

Page 12

Web Programming Lab.

PROGRAM #4

<!--(a)Develop and demonstrate using java script, a XHTML document that collects the USN (the valid format is :a digit from 1 to 4 followed by 2 upper case characters followed by 2 digits followed by 2 upper case characters followed by 3 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 no. from 1 to 8) -- >
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD/XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml10/DTD/xhtml10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> University Seat Number </title> <script type="text/javascript"> function validate() { var usn=document.getElementById("txtusn"); var sem=document.getElementById("txtnum"); if(usn.value==usn.value.match(/[1-4][A-Z]{2}[0-9]{2}[A-Z]{2}[0-9]{3}/)) { if(sem.value==sem.value.match(/[1-8]/)) alert("Entered USN & SEM is valid"); else { alert("Entered sem is invalid"); sem.focus(); return false; } } else { alert("Entries are not valid.Enter valid USN & Sem"); usn.focus(); return false; } } Department of CSE Page 13

Web Programming Lab.

</script> </head> <body > <h1><center>Form to validate USN and Sem</center></h1> <form onsubmit="return validate()" action=""> <table border="0" align="center"> <tr> <th>Enter university seat number </th> <td> <input type="text" id="txtusn" maxlength="10"/></td> </tr> <tr> <th>Enter a semester number</th> <td><input type="text" id="txtnum" maxlength="1"/> </td> </tr> <tr> <td> <input type="submit" value="submit form"/></td> <td> <input type="reset" value="Reset"/></td> </tr> </tbody> </table> </form> </body> </html>

Department of CSE

Page 14

Web Programming Lab.

OUTPUT:

Department of CSE

Page 15

Web Programming Lab.

PROGRAM #5(a)

<!Develop and demonstrate, using javascript script, a XHTML document that contains 3 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 exposed part of any paragraph, it should rise to the top to become completely visible. -->
<?xml version= 1.0 encoding=utf-8 ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/XHTML 10/DTD/XHTML 10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> Dynamic Stack </title> <script type="text/javascript" src="jsc.js"> </script> <style type="text/css"> .para1 { position:absolute; top:0; left:0; z-index:0; background-color:blue; } .para2 { position:absolute; top:50px; left:110px; z-index:0; background-color:red; } .para3 { position:absolute; top:100px; left:220px; z-index:0; background-color:gray; } Department of CSE Page 16

Web Programming Lab.

</style> </head> <body> <div> <p class="para1" id="p1" onmouseover="toTop('p1')"> Hello ,welcome to the site of P.A.College of Engineering. This college is located in Nadupadav near mangalore university The nscd name service cache daemon may now maintain a persistent cache across restarts or system reboots. Each database (user, group, and host, respectively) can be made selected to be persistent by setting the appropriate line in /etc/nscd.conf to "yes". Entries are not removed from the cache until they are proven to be no longer ointerest. All entries whose time-to-live expires but are otherwise interesting are automatically reloaded, which helps in situations where the directory and name service become temporarily unavailable.The nscd name service daemon is also able to communicate faster with client programs. This feature must be enabled explicitly by setting the "shared" entry for the appropriate database in /etc/nscd.conf to "yes". </p> <p class="para2" id="p2" onmouseover="toTop('p2')"> It has a total of six branchs.Including CS,ENC,TE,BT,MECH .This document may be copied and distributed in any medium, either commercially or non-commercially, provided that the GNU Free Documentation License (FDL), the copyright notices, and the license notice saying the GNU FDL applies to the document are reproduced in all copies, and that you add no other conditions whatsoever to those of the GNU FDL.Red Hat, Red Hat Network, the Red Hat "Shadow Man" logo, RPM, Maximum RPM, the RPM logo, Linux Library, PowerTools, Linux Undercover, RHmember, RHmember More, Rough Cuts, Rawhide and all Red Hat-based trademarks and logos are trademarks or registered trademarks of Red Hat, Inc. in the United States and other countries. </p> <p class="para3" id="p3" onmouseover="toTop('p3')"> Certain hardware configurations (particularly those with LCD displays) may experience problems while starting the Fedora Core installation program. In these instances, restart the installation, and add the "nofb" option to the boot command line.NOTE: Chinese, Japanese, and Korean graphical installations started using the "nofb" option will start in English, and then switch to the appropriate language once the graphical phase of the installation process begins.Some Sony VAIO notebook systems may experience problems installing Fedora Core from CD-ROM. If this happens, restart the installation process and add the following option to the boot command line: pci=off ide1=0x180,0x386 This option allows the installation to proceed normally; any devices not detected due to the use of this option will be configured the first time Fedora Core is booted. </p> </div> </body> </html>

Department of CSE

Page 17

Web Programming Lab.

//-------------------------Jscript.js---------------------------------var top="p1"; function toTop(newTop) { var domTop=document.getElementById(top).style; var domNew=document.getElementById(newTop).style; domTop.zIndex="0"; domNew.zIndex="10"; top=newTop; }

Department of CSE

Page 18

Web Programming Lab.

OUTPUT:

Department of CSE

Page 19

Web Programming Lab.

PROGRAM #5(b)

<!-- Modify the above document so that when a paragraph is moved from top stacking position, it returns to its original position rather than to the bottom -->
<?xml version=1.0 encoding=utf-8?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/XHTML 10/DTD/XHTML 10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> Dynamic Stack </title> <script type="text/javascript" src="jscript.js"> </script> <style type="text/css"> .para1 { position:absolute; top:0; left:0; z-index:0; background-color:blue; } .para2 { position:absolute; top:50px; left:110px; z-index:0; background-color:red; } .para3 { position:absolute; top:100px; left:220px; z-index:0; background-color:gray; } </style> </head> Department of CSE Page 20

Web Programming Lab.

<body> <div> <p class="para1" id="p1" onmouseover="toTop('p1')" onmouseout="toOriginal()"> Hello ,welcome to the site of P.A.College of Engineering. This college is located in Nadupadav near mangalore university The nscd name service cache daemon may now maintain a persistent cache across restarts or system reboots. Each database (user, group, and host, respectively) can be made selected to be persistent by setting the appropriate line in /etc/nscd.conf to "yes". Entries are not removed from the cache until they are proven to be no longer of interest. All entries whose time-to-live expires but are otherwise interesting are automatically reloaded, which helps in situations where the directory and name services become temporarily unavailable.The nscd name service daemon is also able to communicate faster with client programs. This feature must be enabled explicitly by setting the "shared" entry for the appropriate database in /etc/nscd.conf to "yes". </p> <p class="para2" id="p2" onmouseover="toTop('p2')" onmouseout="toOriginal()" > It has a total of six branchs.Including CS,ENC,TE,BT,MECH,This document may be copied and distributed in any medium, either commercially or non-commercially, provided that the GNU Free Documentation License (FDL), the copyright notices, and the license notice saying the GNU FDL applies to the document are reproduced in all copies, and that you add no other conditions whatsoever to those of the GNU FDL.Red Hat, Red Hat Network, the Red Hat "Shadow Man" logo, RPM, Maximum RPM, the RPM logo, Linux Library, PowerTools, Linux Undercover, RHmember, RHmember More, Rough Cuts, Rawhide and all Red Hatbased trademarks and logos are trademarks or registered trademarks of Red Hat, Inc. in the United States and other countries. </p> <p class="para3" id="p3" onmouseover="toTop('p3')" onmouseout="toOriginal()"> Certain hardware configurations (particularly those with LCD displays) may experience problems while starting the Fedora Core installation program. In these instances, restart the installation, and add the "nofb" option to the boot command line.NOTE: Chinese, Japanese, and Korean graphical installations started using the "nofb" option will start in English, and then switch to the appropriate language once the graphical phase of the installation process begins.Some Sony VAIO notebook systems may experience problems installing Fedora Core from CD-ROM. If this happens, restart the installation process and add the following option to the boot command line: pci=off ide1=0x180,0x386 This option allows the installation to proceed normally; any devices not detected due to the use of this option will be configured the first time Fedora Core is booted. </p> </div> </body> </html>

Department of CSE

Page 21

Web Programming Lab.

#-------------------------Jscript.js---------------------------------var top="p1"; function toTop(newTop) { var domTop=document.getElementById(top).style; var domNew=document.getElementById(newTop).style; domTop.zIndex="0"; domNew.zIndex="10"; top=newTop; } function toOriginal() { document.getElementById("p1").style.zIndex=0; document.getElementById("p2").style.zIndex=0; document.getElementById("p3").style.zIndex=0; }

Department of CSE

Page 22

Web Programming Lab.

OUTPUT:

Department of CSE

Page 23

Web Programming Lab.

PROGRAM #6(a)

<!--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.-->
<?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/css" href="template.css"?> <students> <student> <USN>4pa06cs001</USN> <name>abc</name> <college>PACE</college> <branch>CS</branch> <year>2006</year> <email>abc@gmail.com</email> </student> <student> <USN>4pa06cs002</USN> <name>def</name> <college>PACE</college> <branch>CS</branch> <year>2006</year> <email>def@gmail.com</email> </student> <student> <USN>4pa06cs003</USN> <name>xyz</name> <college>PACE</college> <branch>CS</branch> <year>2006</year> <email>xyz@yahoo.com</email> </student> </students> //---------------------------- template.css-------------------------USN{color:red;font-family:verdhana;font-size:20pt;} name{color:blue;font-family:verdhana;font-size:20pt;} college{color:black;font-family:verdhana;font-size:20pt;} branch{color:maroon;font-family:verdhana;font-size:20pt;} year{color:purple;font-family:verdhana;font-size:20pt;} email{color:green;font-family:verdhana;font-size:20pt;} student{display:block;margin-top:10px;} heading{display:block;} Department of CSE Page 24

Web Programming Lab.

OUTPUT:

Department of CSE

Page 25

Web Programming Lab.

PROGRAM #6(b) <!--b) Create an XSLT style sheet for one student element of the above document and use it to create a display of that element. -- >
<?xml version="1.0" encoding=utf-8?> <?xml-stylesheet type="text/xsl" href="6b.xsl"?> <students> <student> <USN>4pa06cs001</USN> <name>abc</name> <college>PACE</college> <branch>CS</branch> <year>2006</year> <email>abc@gmail.com</email> </student> <student> <USN>4pa06cs002</USN> <name>def</name> <college>PACE</college> <branch>CS</branch> <year>2006</year> <email>def@gmail.com</email> </student> <student> <USN>4pa06cs003</USN> <name>xyz</name> <college>PACE</college> <branch>CS</branch> <year>2006</year> <email>xyz@yahoo.com</email> </student> </students>

Department of CSE

Page 26

Web Programming Lab.

<!--6b.xsl- ->
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"> <xsl:template match="students"> <html> <body> <h2>STUDENT INFORMATION:</h2> <table border="3"> <tr bgcolor="#9ACD32"> <th>USN</th> <th>NAME</th> <th>COLLEGE</th> <th>BRANCH</th> <th>YEAR OF JOINING</th> <th>EMAIL</th> </tr> <xsl:for-each select="student"> <xsl:if test="position()=1"> <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"/></td> </tr> </xsl:if> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>

Department of CSE

Page 27

Web Programming Lab.

OUTPUT:

Department of CSE

Page 28

Web Programming Lab.

PROGRAM #7(a)

#Write a Perl program to display various server information like Server #Server Software, Server protocol,CGI Revision etc.
#! /usr/bin/perl print "content-type:text/html\n\n <html> <head> <title>Display S.I </title> </head> <body> <center> <h1> <u> server information </u> </h1> <hr> <table border=0 width=40%> <tr> <th> Server name </th> <td> $ENV{'SERVER_NAME'} </td> </tr> <tr> <th> Server port </th> <td> $ENV{'SERVER_PORT'} </td> </tr> <tr> <th> Server software </th> <td> $ENV{'SERVER_SOFTWARE'} </td> </tr> <tr> <th> Server protocol </th> <td> $ENV{'SERVER_PROTOCOL'} </td> </tr> <tr> <th> gateway interface </th> <td> $ENV{'GATEWAY_INTERFACE'} </td> </tr> <tr> <th> Domain name </th> <td>",`/bin/dnsdomainname`,"</td> </tr> <tr> <th> Host name </th> <td>",`/bin/hostname`,"</td> </tr> </table> </hr> </body> </html>"; Department of CSE

Name,

Page 29

Web Programming Lab.

OUTPUT:

Department of CSE

Page 30

Web Programming Lab.

PROGRAM 7(b)

<!- -Write a Perl program to accept UNIX command from a HTML form and to display the output of the command executed- ->
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD/XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml10/DTD/xhtml10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml > <head> <title> Unix Command </title> <script type="text/javascript"> function validate() { var v=document.getElementById("txtcmd").value; if(v=="") { alert("Enter a Unix command"); document.getElementById("txtcmd").focus(); return false; } } </script> </head> <body> <center> <h1> FORM TO EXECUTE A UNIX COMMAND </h1> <form onsubmit="return validate()" action="7b.pl"> <table border="1"> <tr> <td> Enter a Unix command </td> <td> <input type="text" id="txtcmd" name="txtcmd"/> </td> </tr> <tr> <td> <input type="submit" value="Submit"/></td> <td><input type="reset" value="Reset"/></td> </tr> </table> </form> </center> </body> </html>

Department of CSE

Page 31

Web Programming Lab.

#-----------------------7b.pl-------------------------#! /usr/bin/perl -w use CGI':standard'; use strict; print "content-type:text/html \n\n"; my ($cmd,$status); $cmd=param('txtcmd'); print "<center> <b> <h1>"; $status=system($cmd); if($status!=0) { print "Invalid Unix command"; } print "</h1> </b> </center>"; exit(0);

Department of CSE

Page 32

Web Programming Lab.

OUTPUT:

Department of CSE

Page 33

Web Programming Lab.

PROGRAM #8(a)

<!-- Write a perl program to accept the username and display greeting message randomly chosen from a list of greeting messages
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/XHTML10/DTD/XHTML 10.dtd"> <html xmlns="http:www.w3.org/1999/xhtml"> <head> <title>Display Greetings</title> <script type-"text/javascript"> function validate() { var usn=document.write.getElementById("txt"); if(usn.value=="") { alert("Enter the username"); usn.focus(); return false; } } </script> </head> <body bgcolor="beige"> <form onsubmit="retuyrn validate()" action="8a.pl"> <br/><br/><br/><br/><br/> <table border="5" align="center" bgcolor="pink"> <tbody align="center"> <tr> <td>Enter the username</td> <td><input type="text" name="txt" id-"txt"/></td> </tr> <tr> <td><input type="submit" value="SUBMIT"/></td> <td><input type="reset" value="RESET"/></td> </tr> </tbody> </table> </form> </body> </html>

Department of CSE

Page 34

Web Programming Lab.

#------------------------8a.pl---------------------------------------------------------

#!/usr/bin/perl -w use CGI':standard'; my @msgs="Good Morning","Welcome to Web Programming Lab","Have a nice day","Welcome to P.A.C.E"); print "Content-type:text/html \n\n"; $q-int (rand(4)); $nm=param('txt'); print "<html> <body bgcolor=\"pink\"><b><center>"; print "Hello $nm, $msgs[$q]! </b></center>"; print "</body> </html>";

Department of CSE

Page 35

Web Programming Lab.

OUTPUT:

(a)

(b)

Hello sumana, Good Morning!

Department of CSE

Page 36

Web Programming Lab.

PROGRAM 8(b)

#Write a Perl program to keep track of number of visitors visiting the web page #and to display this count of visitors , with proper headings.
#!/usr/bin/perl -w use CGI :standard my $count ; open(FH, <test.txt); $count=<FH>; close(FH); $count++; open(FH, >test.txt); print FH, $count; close(FH); print Content-type:text/html \n\n; print <html><body><h3> <center>; print The web page is visited $count time(s) print </center></h3></body></html>;

Department of CSE

Page 37

Web Programming Lab.

OUTPUT:

The web page is visited 10 time(s)

Department of CSE

Page 38

Web Programming Lab.

PROGRAM #9

#Write a Perl program to display a digital clock which displays the current time of #the server
#!/user/bin/perl $str=A.M.; ($sec,$min,$hour)=localtime(); if($hour>12) { $str=P.M.; $hour - =12; } print content-type:text/html\nRefresh:1\n <html> <head> <title>CLOCK</title> </head> <body><center>DIGITAL CLOCK</center><br/> <center>Server Time: </center><br/>; printf <center>%02d:%02d:%02d%s,$hour,$min,$sec,$str; print </center></body></html>;

Department of CSE

Page 39

Web Programming Lab.

OUTPUT:

DIGITAL CLOCK

Server time:
11:50:30 A.M.

Department of CSE

Page 40

Web Programming Lab.

PROGRAM # 10

<!--Write a Perl program to insert name & age information entered by the user into a table created using MySQL & to display the current contents of this table-->
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/XHTML10/DTD/XHTML 10.dtd"> <html xmlns="http:www.w3.org/1999/xhtml"> <head> <title> Personal Information </title> <script type="text/javascript"> function fun() { var v=document.getElementById("pname"); if(v.value=="") { alert("Please enter name"); document.getElementById("pname").focus(); return false; } var v=document.getElementById("age"); if(v.value=="") { alert("Please enter age"); document.getElementById("age").focus(); return false; } } </script> </head> <body> <h1 align="center"> Form to insert values into table </h1> <table border="1" align="center"> <form onsubmit="return fun()" action="prog10.pl"> <tr> <td>Enter Name: </td> <td><input type="text" id="pname" name="pname"/> </td> </tr> <tr> <td> Enter Age: </td> <td> <input type="text" id="age" name="age"/> </td> </tr> <tr>

Department of CSE

Page 41

Web Programming Lab.

<td> <input type="submit" value="Submit"/></td> <td> <input type="reset" value="Reset"/></td> </tr> </form> </table> </body> </html> # -----------------------------Prog10.pl------------------------------#!/usr/bin/perl -w use DBI; use strict; use CGI':standard'; my ($name,$age); $name=param('pname'); $age=param('age'); my $dbh=DBI->connect('DBI:mysql:csXX','csXX','XXXX') or die "Cannot connect ".DBI->errstr(); my $sth=$dbh->prepare('insert into Personal_info values(?,?)') or die "cannot prepare SQL".$dbh->errstr(); $sth->execute($name,$age) or die "cannot execute".$sth->errstr(); $sth->finish(); my $st=$dbh->prepare('select * from Personal_info') or die "cannot prepare SQL".$dbh->errstr(); $st->execute() or die "cannot execute".$st->errstr(); print "content-type:text/html \n\n"; print "<html> <body> <table border=2> <caption> Personal Information </caption> <tr> <th> Name </th> <th> Age </th> </tr>"; while(($name,$age)=$st->fetchrow()) { print " <tr> <td> $name </td> <td> $age </td> </tr>"; } print " </table> </body> </html>"; $st->finish(); $dbh->disconnect(); Department of CSE Page 42

Web Programming Lab.

OUTPUT:

(a)

(b)

Department of CSE

Page 43

Web Programming Lab.

PROGRAM #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
<?php $duration=time()+60*60*24*60; $found=0; if(isset($_COOKIE['visit'])) { $found=1; $lastvisit=$_COOKIE['visit']; } setcookie(visit,date("m/d/y-G:i:s"),$duration); print <center>; if($found==1) { echo "Welcome back, You have visited on ".$lastvisit; } else { echo "Welcome to this website"; } print </center>; ?>

Department of CSE

Page 44

Web Programming Lab.

OUTPUT:

(a)

Welcome to this website

(b)

Welcome back,you have last visited on 11/21/09:3:38:37

Department of CSE

Page 45

Web Programming Lab.

PROGRAM #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(); session_register("count"); print <center>; if(!isset($_SESSION)) { $_SESSION["count"]=1; echo "counter initialized \n"; } else { $counter=$_SESSION["count"]; $counter=$counter+1; $_SESSION["count"]=$counter; } echo "The counter is now <b> $count</b>"; print </center>; ?>

Department of CSE

Page 46

Web Programming Lab.

OUTPUT:

(a)

Counter initialized
(b)

The counter is now 3

Department of CSE

Page 47

Web Programming Lab.

PROGRAM #13

<!--Create an 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. -->
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/XHTML10/DTD/XHTML 10.dtd"> <html xmlns="http:www.w3.org/1999/xhtml"> <head> <title> Mysql </title> <script type="text/javascript"> function fun() { var v=document.getElementById("name"); if(v.value=="") { alert("Please enter name"); document.getElementById("name").focus(); return false; } var v=document.getElementById("add1"); if(v.value=="") { alert("Please enter address1"); document.getElementById("add1").focus(); return false; } var v=document.getElementById("add2"); if(v.value=="") { alert("Please enter address2"); document.getElementById("add2").focus(); return false; } var v=document.getElementById("email"); if(v.value=="") { alert("Please enter email"); document.getElementById("email").focus(); return false; } } Department of CSE Page 48

Web Programming Lab.

function fun1() { var k=document.getElementById("nam"); if(k.value=="") { alert("Please enter name"); document.getElementById("nam").focus(); return false; } } </script> </head> <body> <h1 align="center"> Form to insert values into table </h1> <table border="1" align="center"> <form onsubmit="return fun()" action="prog13.php"> <tr> <td> Name:</td> <td> <input type="text" id="name" name="name"/> </td> </tr> <tr> <td> Add1:</td> <td> <input type="text" id="add1" name="add1"/> </td> </tr> <tr> <td> Add2:</td> <td> <input type="text" id="add2" name="add2"/> </td> </tr> <tr> <td> Email:</td> <td> <input type="text" id="email" name="email"/> </td> </tr> <tr> <td> <input type="submit" value="submit"/> <input type="reset" value="reset"/> </td> </tr> </form> </table> <hr/> <h1 align="center"> Form to retrieve values based on Name </h1> <table border="1" align="center"> <form onsubmit="return fun1()" action="prog13b.php"> <tr> <td>NAME:</td> Department of CSE Page 49

Web Programming Lab.

<td><input type="text",id="nam" name="nam"/> </td> </tr> <tr> <td> <input type="submit" value="submit"/></td> </tr> </form> </table> </body> </html> //--------------------------------prog13.php--------------------------------<?php $name=$_GET["name"]; $add1=$_GET["add1"]; $add2=$_GET["add2"]; $email=$_GET["email"]; $mysql=mysql_connect("localhost","csXX","XXXX") or die("cannot connect".mysql_error()); $query="insert into tablename values('$name','$add1','$add2','$email')"; mysql_db_query("csXX",$query) or die("error in inserting"); print "Successfully inserted!"; $query="select * from tablename"; $result=mysql_db_query("csXX",$query) or die("error in selecting"); print "<br/>"; print "<table border=1>"; while($array=mysql_fetch_row($result)) { print "<tr>"; foreach($array as $f) { print "<td>"; print "$f "; print "</td>"; } print "</tr>"; } print "</table>"; mysql_close($mysql); ?>

Department of CSE

Page 50

Web Programming Lab.

//------------------------------prog13b.php---------------------------------<?php $nam=$_GET['nam']; $mysql=mysql_connect("localhost","cs31","2588") or die("cannot connect");

$query="select * from tablename where name='$nam'"; $result=mysql_db_query("cs31",$query) or die("error in the query"); if( mysql_num_rows($result)==0) echo "no record found"; else { while($array=mysql_fetch_row($result)) { foreach($array as $f) print "$f "; print "<br>"; } } mysql_close($mysql); ?>

Department of CSE

Page 51

Web Programming Lab.

OUTPUT: (a)

(b)

Department of CSE

Page 52

Web Programming Lab.

(c)

(d)

Department of CSE

Page 53

Web Programming Lab.

PROGRAM #14

<!--Using PHP and MySQL develop a program to accept book information viz. Accession number,title,authors,edition and publisher from 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 -->
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD/XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml10/DTD/xhtml10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> Mysql </title> <script type="text/javascript"> function fun() { var v=document.getElementById("accno"); if(v.value=="") { alert("Please enter the accession num"); document.getElementById("accno").focus(); return false; } var v=document.getElementById("tit"); if(v.value=="") { alert("Please enter the title"); document.getElementById("tit").focus(); return false; } var v=document.getElementById("aut"); if(v.value=="") { alert("Please enter author name"); document.getElementById("aut").focus(); return false; } var v=document.getElementById("edi"); if(v.value=="") { alert("Please enter the edition"); document.getElementById("edi").focus(); return false; } var v=document.getElementById("pub"); Department of CSE Page 54

Web Programming Lab.

if(v.value=="") { alert("Please enter the publisher name"); document.getElementById("pub").focus(); return false; } } function fun1() { var k=document.getElementById("title"); if(k.value=="") { alert("Please enter title"); document.getElementById("title").focus(); return false; } } </script> </head> <body> <h1 align="center"> Form to insert values into table </h1> <table border="1" align="center"> <form onsubmit="return fun()" action="prog14.php"> <tr> <td> ACCESSION NUMBER:</td> <td> <input type="text" id="accno" name="accno"/> </td> </tr> <tr> <td> TITLE:</td> <td> <input type="text" id="tit" name="tit"/> </td> </tr> <tr> <td> AUTHOR:</td> <td> <input type="text" id="aut" name="aut"/> </td> </tr> <tr> <td> EDITION:</td> <td> <input type="text" id="edi" name="edi"/> </td> </tr> <tr> <td> PUBLISHER:</td> <td> <input type="text" id="pub" name="pub"/> </td> </tr> <tr> <td> <input type="submit" value="submit"/> </td> Department of CSE Page 55

Web Programming Lab.

<td> <input type="reset" value="reset"/> </td> </tr> </form> </table> <hr/> <h1 align="center"> Form to retrieve values based on Title </h1> <table border="1" align="center"> <form onsubmit="return fun1()" action="prog14b.php"> <tr> <td>TITLE:</td> <td><input type="text" id="title" name="title"/> </td> </tr> <tr> <td> <input type="submit" value="submit"/> </td> <td> input type="reset" value="reset"/></td> </tr> </form> </table> </body> </html> //--------------------------------prog14.php--------------------------------<?php $acc=$_GET["accno"]; $title=$_GET["tit"]; $author=$_GET["aut"]; $edition=$_GET["edi"]; $publ=$_GET["pub"]; $mysql=mysql_connect("localhost","csXX","XXXX") or die("cannot connect"); $query="insert into tablename values('$acc','$title','$author','$edition','$publ')"; mysql_db_query("csXX",$query) or die("error in inserting"); print "<center>Successfully inserted!</center>"; $query="select * from tablename"; $result=mysql_db_query("csXX",$query) or die("error in selecting"); print "<br/>"; print "<table border=1>"; while($array=mysql_fetch_row($result)) { print "<tr>"; foreach($array as $f) { print "<td>"; Department of CSE Page 56

Web Programming Lab.

print "$f "; print "</td>"; } print "</tr>"; } print "</table>"; mysql_close($mysql); ?> //------------------------------prog14b.php---------------------------------<?php $titl=$_GET['title']; $mysql=mysql_connect("localhost","csXX","XXXX") or die("cannot connect"); $query="select * from tablename where title='$titl'"; $result=mysql_db_query("csXX",$query) or die("error in the query"); if( mysql_num_rows($result)==0) echo "no record found"; else { while($array=mysql_fetch_row($result)) { foreach($array as $f) print "$f "; print "<br>"; } } mysql_close($mysql); ?>

Department of CSE

Page 57

Web Programming Lab.

OUTPUT: (a)

(b)

Department of CSE

Page 58

Web Programming Lab.

(c)

(d)

Department of CSE

Page 59

S-ar putea să vă placă și