0% found this document useful (0 votes)
204 views71 pages

Ip Lab New PDF

The document describes simulations of file transfer protocols using TCP. It provides algorithms for a client-server model: The server program creates a socket, binds it to a port, listens for connections and accepts a client connection. It receives a file name from the client, opens the file, reads it and sends the contents to the client. The client program creates a socket, connects to the server's port, sends the file name and receives the file contents from the server. It writes the received contents to a new file. Both programs are implemented in C using TCP sockets for connection establishment and file transfer. The server forks a child process to handle each client connection concurrently.

Uploaded by

Nivitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
204 views71 pages

Ip Lab New PDF

The document describes simulations of file transfer protocols using TCP. It provides algorithms for a client-server model: The server program creates a socket, binds it to a port, listens for connections and accepts a client connection. It receives a file name from the client, opens the file, reads it and sends the contents to the client. The client program creates a socket, connects to the server's port, sends the file name and receives the file contents from the server. It writes the received contents to a new file. Both programs are implemented in C using TCP sockets for connection establishment and file transfer. The server forks a child process to handle each client connection concurrently.

Uploaded by

Nivitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 71

ExNo :01

Date

DesigningWebPagesusingClientSideScriptingandDHTML

Aim:
TodesignaWebPageusingClientSideScriptingandDHTML.

Algorithm:
1.Starttheprogram
2.Theformwillincludetextfieldscalled"FirstName",lastName,Addressetc
3.Validationscriptwillensurethattheuserenterstheirnamebeforetheformissenttothe
server.
4.Openthispagetoseeitinaction.
5.TrypressingthePlaceOrderbuttonwithoutfillinganythingfieldwillreturnnullorder
6.Youmightliketoopenthesourcecodeforthisforminaseparatewindowthepage
consistsofaJavaScriptfunctioncalledvalidate_form()thatperformstheformvalidation,
followedbytheformitself.
SourceCode:
<html>
<head>
<scripttype="text/javascript">
functionblinking_header()
{
if(!document.getElementById('blink').style.color)
{
document.getElementById('blink').style.color="red";
}
if(document.getElementById('blink').style.color=="red")
{
document.getElementById('blink').style.color="black";
}
else
{
5108 GTEC

IT9225 Internet Programming Lab

document.getElementById('blink').style.color="red";
}
timer=setTimeout("blinking_header()",100);
}
functionstoptimer()
{
clearTimeout(timer);
}
</script>
</head>
<bodyonload="blinking_header()"onunload="stoptimer()">
<h1id="blink">Blinkingheader</h1>
<formname="OrderForm">
<tableborder=2width="75%">
<tr>
<td>
<i>FirstName</i>
</td>
<td> <input type="text" name="Firstname" size=30 onfocus="window.status='Enter ur
firstnameplease'">
</td>
</tr>
<tr>
<td>
<i>LastName</i>
</td>
<td> <input type="text" name="lastname" size=30 onfocus="window.status='Enter ur
lastnameplease'">
</td>
</tr>
<tr>
<td>
<i>Address<i>
</td>
<tdcolspan="3">
<input type="text" name="address" size=30 onfocus="window.status='Enter ur
mailungaddressplease'">
</td>
5108 GTEC

IT9225 Internet Programming Lab

</tr>
<tr>
<td>
<i>City</i>
</td>
<td>
<inputtype="text"name="city"size=30onfocus="window.status='Enterurcityplease'">
</td>
</tr>
<tr>
<td>
<i>State</i>
</td>
<td>
<inputtype="text"name="state"size=30onfocus="window.status='Enterurstateplease'">
</td>
</tr>
<tr>
<td>
<i>ZIP</i>
</td>
<td> <input type="text" name="zip" size=10 onfocus="window.status='Enter ur PIn
please'">
</td>
</tr>
</table>
<p>
<center>
woulduliketobeinurmailinglist
<inputtype="checkbox"name="list"checkedonclick="notify()">Yes
</center>
<p>
<hrwidh=50%align=center>
<p>
<selectname="orderitem">
<optionvalue="8.95">Grey
<optionvalue="12.95">Color
<optionvalue="24.99">OurMidRangeItem
5108 GTEC

IT9225 Internet Programming Lab

<optionvalue="99.95">SuperDeluxe
</select>SelecttheItemuwant
<p>
<selectname="Qty">
<optionvalue="1">One
<optionvalue="2">Two
<optionvalue="3">Three
<optionvalue="4">Four
</select>Selecttheqtyofitemstoorder
</b>
<p>
TotalDue
<inputtype=textname="total"size=11onfocus="totalorder(this.form)">
<hr>
<p>
<inputtype=submitvalue="Placeorder">
<inputtype=resetvalue="cleartheform">
</form><scriptlanguage="javascript">functionnotify()
{
alert("Pleasebeawarethatmailinglistisforinternaluse");
}
functiontotalorder(form)
{
varx=form.orderitem.options[form.orderitem.selectedIndex].value;
vary=form.Qty.options[form.Qty.selectedIndex].value;
vardue=x*y;
form.total.value=due;
}
</script>
</body>
</html>
Output:
TotalOrderForm:

5108 GTEC

IT9225 Internet Programming Lab

Result:
ThusthedesigningwebpagesusingclientsidescriptingandDHTMLhasbeen
executedandverifiedsuccessfully.

ExNo :02
Date

ClientServerScriptingPrograms

Aim:
TodevelopasimpleClientServerScriptingProgramsinasinglewebpage.
5108 GTEC

IT9225 Internet Programming Lab

Algorithm:
1.Starttheprogram
2.Createaservervariable,MyServerVar,andaclientvariable,MyClientVar.
3.Itprintssimpletextstringstoidentifyeachvalue.
4.Theservercodemarkedwiththeserverscripttags,<%%>andtheclientscriptshown
with<SCRIPT>tags.
5.Stoptheprogram.

SourceCode:
ServerScriptingProgram
<%@LANGUAGE="VBSCRIPT"%>
<HTML>
<HEAD>
<METANAME="GENERATOR"Content="MicrosoftVisualInterDev1.0">
<METAHTTPEQUIV="ContentType"content="text/html;charset=iso88591">
<TITLE>SampleScriptEvaluation</TITLE>
</HEAD>
<BODY>
<***ServerScript***>
<%MyServerVar=6%>
<P>Thisvaluewasevaluatedontheserver"<%MyServerVar%>"</P>
<***ClientScriptwithaServerScriptVariable***>
<SCRIPTLANGUAGE="jscript">
<!varMyClientVar;
MyClientVar=(<%=MyServerVar%>+1);
document.write('<P>Thisvalueisaclientvalue'+MyClientVar+'</P>');
if(MyClientVar==42)
{
document.write('<P>Theserverandclientvaluesareequal'+MyClientVar+'</P>');
}
else
{

5108 GTEC

IT9225 Internet Programming Lab

document.write("<P>Theserverandclientvaluearenotequalbecauseourscripttoldthe
clienttoadd1.</P>");
}
//
>
</SCRIPT>
</BODY>
</HTML>
Clientscriptingprogram
<HTML>
<HEAD>
<METANAME="GENERATOR"Content="MicrosoftVisualInterDev1.0">
<METAHTTPEQUIV="ContentType"content="text/html;
charset=iso88591">
<TITLE>SampleScriptEvaluation</TITLE>
</HEAD>
<BODY>
<***ServerScriptwashere***>
<P>Thisvaluewasevaluatedontheserver6</P>
<***ClientScriptisherewiththeValuefromtheServerVariable***>
<SCRIPTLANGUAGE="jscript">
<!varMyClientVar;
MyClientVar=(6+1);
document.write('<P>Thisvalueisaclientvalue'+MyClientVar+'</P>');
if(MyClientVar==42)
{
document.write('<P>Theserverandclientvaluesareequal:'+MyClientVar+'</P>');
}
else
{
document.write("<P>Theserverandclientvaluearenotequalbecauseourscripttoldthe
clienttoadd1.</P>");
}
//
>
</SCRIPT>
5108 GTEC

IT9225 Internet Programming Lab

</BODY>
</HTML>
Output:
SampleScriptEvaluation:

Result:
ThustheClientServerScriptingProgramshasbeenexecutedandverifiedsuccessfully

ExNo :03
Date

SimulationofEmailandFileTransferProtocols

Aim:
TowriteaCprogramfortransferringafileusingTCP.
Algorithm:
Server:
5108 GTEC

IT9225 Internet Programming Lab

Step1:Starttheprogram.
Step2:CreateanunnamedsocketfortheserverusingparametersAF_INETas domain
andSOCK_STREAMastype.
Step3:Gettheserverportnumber.
Step4:Registerthehostaddresstothesystembyusingbind()systemcallinserverside.
Step5:Createaconnectionqueueandwaitforclientsusinglisten()systemcallwiththe
numberofclientsrequestsasparameter.
Step6:CreateaChildprocessusingfork()systemcall.
Step7:Iftheprocessidentificationnumberisequaltozeroaccepttheconnection using
accept()systemcallwhentheclientrequestforconnection.
Step8:Ifpidisnotequaltozerothenexittheprocess.
Step9:StoptheProgramexecution.

Client:
Step1:Starttheprogram.
Step2:CreateanunnamedsocketfortheclientusingparametersAF_INETasdomainand
SOCK_STREAMastype.
Step3:Gettheclientportnumber.
Step4:Nowconnectthesockettoserverusingconnect()systemcall.
Step5:Enterthefilename.
Step6:Thefileistransferredfromclienttoserverusingsend()function.
Step7:Printthecontentsofthefileinanewfile.
Step8:Stoptheprogram.
SourceCode:

SimulationofFileTransferProtocols
Server:
#include<stdio.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<string.h>
5108 GTEC

IT9225 Internet Programming Lab

main()
{
FILE*fp;
intsd,newsd,ser,n,a,cli,pid,bd,port,clilen;
charname[100],fileread[100],fname[100],ch,file[100],rcv[100];
structsockaddr_inservaddr,cliaddr;
printf("Entertheportaddress:");
scanf("%d",&port);
sd=socket(AF_INET,SOCK_STREAM,0);
if(sd<0)
printf("Can'tCreate\n");
else
printf("SocketisCreated\n");
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
servaddr.sin_port=htons(port);
a=sizeof(servaddr);
bd=bind(sd,(structsockaddr*)&servaddr,a);
if(bd<0)
printf("Can'tBind\n");
else
printf("\nBinded\n");
listen(sd,5);
clilen=sizeof(cliaddr);
newsd=accept(sd,(structsockaddr*)&cliaddr,&clilen);
if(newsd<0)
printf("Can'tAccept\n");
else
printf("Accepted\n");
n=recv(newsd,rcv,100,0);
rcv[n]='\0';
fp=fopen(rcv,"r");
if(fp==NULL)
{
send(newsd,"error",5,0);
close(newsd);
}
else
5108 GTEC

10

IT9225 Internet Programming Lab

{
while(fgets(fileread,sizeof(fileread),fp))
{
if(send(newsd,fileread,sizeof(fileread),0)<0)
{
printf("Can'tsend\n");
}
sleep(1);
}
if(!fgets(fileread,sizeof(fileread),fp))
{
send(newsd,"completed",999999999,0);
}
return(0);
}
}

Client:
#include<stdio.h>
#include<sys/socket.h>
#include<netinet/in.h>
main()
{
FILE*fp;intcsd,n,ser,s,cli,cport,newsd;
charname[100],rcvmsg[100],rcvg[100],fname[100];
structsockaddr_inservaddr;
printf("Entertheport");
scanf("%d",&cport);
csd=socket(AF_INET,SOCK_STREAM,0);
if(csd<0)
{
printf("Error...");
exit(0);
}
else
printf("SocketisCreated...\n");
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
5108 GTEC

11

IT9225 Internet Programming Lab

servaddr.sin_port=htons(cport);
if(connect(csd,(structsockaddr*)&servaddr,sizeof(servaddr))<0)
printf("ErrorinConnection...\n");
else
printf("Connected...\n");
printf("Entertheexistingfilename:");
scanf("%s",name);
printf("\nEnterthenewfilename:");
scanf("%s",fname);
fp=fopen(fname,"w");
send(csd,name,sizeof(name),0);
while(1)
{
s=recv(csd,rcvg,100,0);
rcvg[s]='\0';
if(strcmp(rcvg,"error")==0)
printf("FileisnotAvailable...\n");
if(strcmp(rcvg,"completed")==0)
{
printf("fileistransferred...\n");
fclose(fp);
close(csd);
break;
}
else
fputs(rcvg,stdout);
fprintf(fp,"%s",rcvg);
}
}
Output:

ServerSide
[1me16@localhost~]$ccftpclient.c
[1me16@localhost~]$./a.out
Entertheportaddress:8663
SocketisCreatedBinded
Connected
5108 GTEC

12

IT9225 Internet Programming Lab


ClientSide
[1me16@localhost~]$ccftpserver.c
[1me16@localhost~]$./a.out
SocketisCreated..
Connected
Entertheexistingfilename:net
Enterthenewfilename:network
WelcometoNetworkLab
Fileistransferred...

SimulationofEmail

#include<stdlib.h>
#include<string.h>
#definecknull(x)if((x)==NULL){perror("");exit(EXIT_FAILURE);}
#definecknltz(x)if((x)<0){perror("");exit(EXIT_FAILURE);}
#defineLIST_LEN4
//char*f="sam.txt";
voidemail_it(char*filename);
main()
{
charfname[15];
printf("enterthefilename\n");
scanf("%s",fname);
email_it(fname);
}
voidemail_it(char*filename)
{
chartmp[256]={0x0};
charfpBuffer[400]={0x0};
charemail_list[LIST_LEN][256]={{"[email protected]"},{0x0}};
inti=0;
for(i=0;*email_list[i]>0x0;i++)
{
cknull(strcpy(tmp,email_list[i]));
cknltz(sprintf (fpBuffer,"mail s '%s %s' %s < %s", "Please Review:", filename,
tmp,filename));
5108 GTEC

13

IT9225 Internet Programming Lab

if(system(fpBuffer)==(1))
{
perror("emailfailure");
exit(EXIT_FAILURE);
}
}
}

Output:

[1me2@localhost~]$viemail.c
[1me2@localhost~]$ccemail.c
[1me2@localhost~]$/a.out
Enterthefilename:sample.c
[1me2@localhost~]$/home/1me1/dead.letter.savedmessagein
/home/1me1/dead.letter..

5108 GTEC

14

IT9225 Internet Programming Lab

Result:

ThustheprogramfordevelopingEmailandfiletransferprotocolsapplicationhas
beenexecutedandverifiedsuccessfully.

ExNo :04
Date

DevelopmentofWebServices

Aim:
TodevelopawebserviceprogramforcalculatingFactorialofanumber.

Algorithm:
1.Starttheprogram.
2.Giveoneparameternamex
3.Datatypeasint
4.Clickonok
5.ThiswillcreatetheWebServicecodewiththenameasfactorialandmethodnameas
fact1
6.Thiswillbehavingtheannotationas@Webservice,@Webmethodand@Webparam
7.Stoptheprogram
SourceCode:
packagepack1;
importjavax.jws.WebMethod;
5108 GTEC

15

IT9225 Internet Programming Lab

importjavax.jws.WebParam;
importjavax.jws.WebService;
@WebService()
publicclassfactorial
{
intfact=1;
@WebMethod(operationName="fact1")
publicStringfact1(@WebParam(name="x")intx)
{
for(inty=1;y<=x;y++)
{
fact=fact*y;
}
return"factorialof"+x+"is"+fact;
}
}
packagepack1;
publicclassClient1
{
publicstaticvoidmain(String[]args)
{
try
{
pack1.FactorialServiceservice=newpack1.FactorialService();
pack1.Factorialport=service.getFactorialPort();
intx=5;
java.lang.Stringresult=port.fact1(x);
System.out.println("Result="+result);
}
catch(Exceptionex)
{
ex.printStackTrace();
}
}
}

5108 GTEC

16

IT9225 Internet Programming Lab

Output:
Webserviceprogramforfactorialofanumber:

5108 GTEC

17

IT9225 Internet Programming Lab

Result:
Thus the Client Server Scripting Programs has been executed and verified
successfully.

ExNo :05
Date

XMLandDatabases

Aim:
ToParsinganXMLdocumentusingDOMandSAXParsers.

Algorithm:
UsingDom:
Step1:Getadocumentbuilderusingdocumentbuilderfactoryandparsethexmlfileto
createaDOMobject.
Step2:GetalistofemployeeelementsfromtheDOM.
Step3:Foreachemployeeelementgettheid,name,ageandtype.
Createanemployeevalueobjectandaddittothelist.
Step4:Attheenditeratethroughthelistandprinttheemployeestoverifyweparsedit
right.

UsingSax
Step1:CreateaSaxparserandparsethexml
Step2:Intheeventhandlercreatetheemployeeobject
Step3:Printoutthedata

SourceCode:
UsingSax:
5108 GTEC

18

IT9225 Internet Programming Lab

employees.xml
<?xmlversion="1.0"encoding="UTF8"?>
<Personnel>
<Employeetype="permanent">
<Name>Seagull</Name>
<Id>3674</Id>
<Age>34</Age>
</Employee>
<Employeetype="contract">
<Name>Robin</Name>
<Id>3675</Id>
<Age>25</Age>
</Employee>
<Employeetype="permanent">
<Name>Crow</Name>
<Id>3676</Id>
<Age>28</Age>
</Employee>
</Personnel>
DomParserExample.java
a) Gettingadocumentbuilder
privatevoidparseXmlFile(){
//getthefactory
DocumentBuilderFactorydbf=
DocumentBuilderFactory.newInstance();
try{
//Usingfactorygetaninstanceofdocumentbuilder
DocumentBuilderdb=dbf.newDocumentBuilder();
//parseusingbuildertogetDOMrepresentationofthe
XMLfile
dom=db.parse("employees.xml");
}catch(ParserConfigurationExceptionpce){
pce.printStackTrace();
}catch(SAXExceptionse){
se.printStackTrace();
}catch(IOExceptionioe){
ioe.printStackTrace();
5108 GTEC

19

IT9225 Internet Programming Lab

}
}

b) Getalistofemployeeelements
Get the rootElement from the DOM object.From the root element get all employee
elements.Iteratethrougheachemployeeelementtoloadthedata.
privatevoidparseDocument(){
//gettherootelement
ElementdocEle=dom.getDocumentElement();
//getanodelistofelements
NodeListnl=docEle.getElementsByTagName("Employee");
if(nl!=null&&nl.getLength()>0){
for(inti=0;i<nl.getLength();i++){
//gettheemployeeelement
Elementel=(Element)nl.item(i);
//gettheEmployeeobject
Employeee=getEmployee(el);
//addittolist
myEmpls.add(e);
}
}
}
c) Readingindatafromeachemployee.
/**
*Itakeanemployeeelementandreadthevaluesin,create
*anEmployeeobjectandreturnit
*/
privateEmployeegetEmployee(ElementempEl){
//foreach<employee>elementgettextorintvaluesof
//name,id,ageandname
Stringname=getTextValue(empEl,"Name");
intid=getIntValue(empEl,"Id");
intage=getIntValue(empEl,"Age");
Stringtype=empEl.getAttribute("type");
//CreateanewEmployeewiththevaluereadfromthexmlnodes
5108 GTEC

20

IT9225 Internet Programming Lab

Employeee=newEmployee(name,id,age,type);
returne;
}
/**
*Itakeaxmlelementandthetagname,lookforthetagandget
*thetextcontent
*i.efor<employee><name>John</name></employee>xmlsnippetif
*theElementpointstoemployeenodeandtagNameis'name'Iwill
returnJohn
*/
privateStringgetTextValue(Elementele,StringtagName){
StringtextVal=null;
NodeListnl=ele.getElementsByTagName(tagName);
if(nl!=null&&nl.getLength()>0){
Elementel=(Element)nl.item(0);
textVal=el.getFirstChild().getNodeValue();
}
returntextVal;
/**
*CallsgetTextValueandreturnsaintvalue
*/
privateintgetIntValue(Elementele,StringtagName){
//inproductionapplicationyouwouldcatchtheexception
returnInteger.parseInt(getTextValue(ele,tagName));
}
d) Iteratingandprinting.
privatevoidprintData(){
System.out.println("NoofEmployees'"+myEmpls.size()+"'.");
Iteratorit=myEmpls.iterator();while(it.hasNext()){
System.out.println(it.next().toString());
}
}

5108 GTEC

21

IT9225 Internet Programming Lab

UsingSax:
SAXParserExample.java
a) CreateaSaxParserandparsethexml
privatevoidparseDocument(){
//getafactory
SAXParserFactoryspf=SAXParserFactory.newInstance();
try{
//getanewinstanceofparser
SAXParsersp=spf.newSAXParser();
//parsethefileandalsoregisterthisclassforcallbacks
sp.parse("employees.xml",this);}
catch(SAXExceptionse){
se.printStackTrace();}
catch(ParserConfigurationExceptionpce){
pce.printStackTrace();}
catch(IOExceptionie){
ie.printStackTrace();
}
}
b) In the event handlers create the Employee object and call the corresponding setter
methods.
//EventHandlers
publicvoidstartElement(Stringuri,StringlocalName,StringqName,Attributesattributes)
throwsSAXException
{
//resettempVal="";
if(qName.equalsIgnoreCase("Employee")){
//createanewinstanceofemployee
tempEmp=newEmployee();
tempEmp.setType(attributes.getValue("type"));
}
}
publicvoidcharacters(char[]ch,intstart,intlength)throwsSAXException
{
tempVal=newString(ch,start,length);}
5108 GTEC

22

IT9225 Internet Programming Lab

public void endElement(String uri, String localName, String qName) throws


SAXException
{
if(qName.equalsIgnoreCase("Employee")){
//addittothelistmyEmpls.add(tempEmp);}
elseif(qName.equalsIgnoreCase("Name"))
{tempEmp.setName(tempVal);}
elseif(qName.equalsIgnoreCase("Id")){
tempEmp.setId(Integer.parseInt(tempVal));
}
}
c)Iteratingandprinting.
privatevoidprintData(){
System.out.println("NoofEmployees'"+myEmpls.size()+"'.");
Iteratorit=myEmpls.iterator();
while(it.hasNext()){
System.out.println(it.next().toString());
}
}

Output:
EmployeeDetailsName:Seagull,Type:permanent,Id:3674,Age:34.
EmployeeDetailsName:Robin,Type:contract,Id:3675,Age:25.
EmployeeDetailsName:Crow,Type:permanent,Id:3676,Age:28.

Result:
ThustheParsinganXMLdocumentusingDOMandSAXParsershasbeenexecuted
andverifiedsuccessfully.

ExNo :06
Date

5108 GTEC

ServerSideApplicationUsingJSP

23

IT9225 Internet Programming Lab

Aim:

TodevelopthestudentwebpageinformationusingjavaservletandJDBC.

Algorithm:
Step1:Starttheprogram
Step2:CreatemainHTMLpageforstudentdatabasemaintenance
Step3:SelectoptiontodothefollowingoperationInsertion,search,deleteandmodifyor
updatethestudentrecode

SourceCode:
Main.Html
<html>
<bodybgcolor=yellowtext=red>
<divalign=center>
<label><h2>Studentdatabasemaintenance</h2></label>
<TABLE>

<TR><TD><a
href="http://localhost:7001/student/register.html">REGISTER</a></TD></TR>
<TR><TD><ahref="http://localhost:7001/student/find3">SEARCH</a></TD></TR>

<TR><TD><a href="http://localhost:7001/student/viewall">VIEW ALL


</a></TD></TR>

<TR><TD><a
href="http://localhost:7001/student/delete2.html">DELETE</a></TD></TR>

<!<TR><TD><a
href="http://localhost:7001/student/update">UPDATE</a></TD></TR>>
</table>
</div>
</body>
Register.HTML
<!DOCTYPEHTMLPUBLIC"//W3C//DTDHTML4.0Transitional//EN">
<HTML>
<HEAD>
<TITLE>registration</TITLE>
</HEAD>
5108 GTEC

24

IT9225 Internet Programming Lab

<BODYbgcolor=teaktext=red>
<formaction="http://localhost:7001/student/register1"method=post>
<pre>
EnterId:<inputtype=textname="id"size=4><br>
EnterName:<inputtype=textname="name"size=20><br>
EnterAge:<inputtype=textname="age"size=4><br>
EnterBranch:<inputtype=textname="branch"size=10><br>
EnterMark1:<inputtype=textname="m1"size=4><br>
EnterMark2:<inputtype=textname="m2"size=4><br>
EnterMark3:<inputtype=textname="m3"size=4><br>
EnterGrade:<inputtype=textname="grade"size=20><br>
Click:<inputtype="submit"name="submit"value=register>
</pre></form></BODY></HTML>
Insert.Html
<!DOCTYPEHTMLPUBLIC"//W3C//DTDHTML4.0Transitional//EN">
<HTML>
<HEAD>
<TITLE>registration</TITLE>
</HEAD>
<BODYbgcolor=teaktext=red>
<formaction="http://localhost:7001/student/insert"method=post>
<pre>
<divalign=center>
EnterId:<inputtype=textname="id"size=4><br>
EnterName:<inputtype=textname="name"size=20><br>
EnterAge:<inputtype=textname="age"size=4><br>
EnterBranch:<inputtype=textname="branch"size=10><br>
EnterMark1:<inputtype=textname="m1"size=4><br>
EnterMark2:<inputtype=textname="m2"size=4><br>
EnterMark3:<inputtype=textname="m3"size=4><br>
EnterGrade:<inputtype=textname="grade"size=4><br>
<inputtype="submit"name="submit"value=register>
</div></pre></form></BODY></HTML>
Delete.Html
<!DOCTYPEHTMLPUBLIC"//W3C//DTDHTML4.0Transitional//EN">
<HTML>
<HEAD>
5108 GTEC

25

IT9225 Internet Programming Lab

<TITLE>DELETESTUDENTRECORD</TITLE>
</HEAD>
<BODYbgcolor=yellowtext=cyan>
<formaction="http://localhost:7001/student/delete2"method=post>
<pre>
EntertheID:<inputtype=textname="idno"size=4><br>
Click:<inputtype="submit"name=submitvalue=delete>
</pre></form></BODY></HTML>
Second.java
importjava.io.*;
importjavax.servlet.*;
importjavax.servlet.http.*;
importjava.sql.*;
importjava.lang.*;
publicclasssecondextendsHttpServlet
{
publicvoiddoGet(HttpServletRequestreq,HttpServletResponseres)throws
ServletException,IOException
{
loginform(res,false);
}//goGet()
privatevoidloginform(HttpServletResponseres,booleanerror)throws
ServletException,IOException{
res.setContentType("text/html");
PrintWriterpr=res.getWriter();
pr.println("<html><bodybgcolor=bluetext=red>");
pr.println("<divalign=center>");
if(error)
{
pr.println("<H2>LOGINFAILED,PLEASETRYAGAIN!!!</H2>");
}
pr.println("<formmethod=postNAME=FORM>");
pr.println("<table><TR><TD><label>pleaseenteryournameand
password</label></TR></TD>");
pr.println("<TR><TD>Username:<inputtype=textname=username>");
pr.println("<TR><TD>Password:<inputtype=password
name=password><br></TR></TD><hrwidth=100%></TR></TD>");
5108 GTEC

26

IT9225 Internet Programming Lab

pr.println("<TR><TD>Press:<inputtype=submitname=submit
value=Continue></TR></TD>");
pr.println("<TR><TD>clear:<inputtype=resetname=reset
value=Clear></TR></TD></TABLE>");
pr.println("</form></div></body></html>");}
//loginform()
publicvoiddoPost(HttpServletRequestreq,HttpServletResponseres)throws
ServletException,IOException{
Stringname=req.getParameter("username");
Stringpass=req.getParameter("password");
if(logindb(name,pass)){
RequestDispatcherrd=req.getRequestDispatcher("/main.html");
rd.forward(req,res);
}else{
loginform(res,true);}}
//doPost()
booleanlogindb(Stringname,Stringpass){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connectioncon=DriverManager.getConnection("jdbc:odbc:logindb");
Statements=con.createStatement();
Stringsql="select*fromstuwhereusername='"+name+"'ANDpassword='"+pass+"'
";
ResultSetrs=s.executeQuery(sql);
if(rs.next()){returntrue;}
con.close();}
catch(SQLExceptions){
s.printStackTrace();
}catch(Exceptione){
e.printStackTrace();}
returnfalse;
}
//login()
};
Register1.jav
/*INSERTINGTHEDATA*/
importjavax.servlet.*;
5108 GTEC

27

IT9225 Internet Programming Lab

importjavax.servlet.http.*;
importjava.io.*;
importjava.util.*;
importjava.sql.*;
importjava.lang.*;
publicclassregister1extendsHttpServlet{
publicvoiddoPost(HttpServletRequestreq,HttpServletResponseres)throws
ServletException,IOException{
try{
res.setContentType("Text/html");
PrintWriterpr=res.getWriter();
intid=Integer.parseInt(req.getParameter("id"));
Stringname=req.getParameter("name");
intage=Integer.parseInt(req.getParameter("age"));
Stringbranch=req.getParameter("branch");
intm1=Integer.parseInt(req.getParameter("m1"));
intm2=Integer.parseInt(req.getParameter("m2"));
intm3=Integer.parseInt(req.getParameter("m3"));
Stringgrade=req.getParameter("grade");
pr.println("<html><bodybgcolor=yellowtext=red><divalign=center>");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connectioncon=DriverManager.getConnection("jdbc:odbc:ss");
//pr.println("studentinformationaresuccessfullyregistered");
//pr.println("<ahref=http://localhost:7001/student/main.html>gotomainpage</a>");
PreparedStatementpst=con.prepareStatement("Insertintostudatavalues(?,?,?,?,?,?,?,?)");
pst.setInt(1,id);
pst.setString(2,name);
pst.setInt(3,age);
pst.setString(4,branch);
pst.setInt(5,m1);
pst.setInt(6,m2);
pst.setInt(7,m3);
pst.setString(8,grade);
pst.executeQuery();
pr.println("studentinformationaresuccessfullyregistered");
pr.println("<ahref=http://localhost:7001/student/main.html>gotomainpage</a>");
pr.println("</html></body>");
con.commit();
5108 GTEC

28

IT9225 Internet Programming Lab

}
catch(SQLExceptione){
System.out.println(e.getMessage());
}catch(Exceptione){e.printStackTrace();
}
}
};
Insert.java
importjavax.servlet.*;
importjavax.servlet.http.*;
importjava.io.*;
importjava.util.*;
importjava.sql.*;
importjava.lang.*;
publicclassregisterextendsHttpServlet
{
publicvoiddoPost(HttpServletRequestreq,HttpServletResponseres)throws
ServletException,IOException
{
try{
res.setContentType("Text/html");
PrintWriterpr=res.getWriter();
intid=Integer.parseInt(req.getParameter("id"));
Stringname=req.getParameter("name");
intage=Integer.parseInt(req.getParameter("age"));
Stringbranch=req.getParameter("branch");
intm1=Integer.parseInt(req.getParameter("m1"));
intm2=Integer.parseInt(req.getParameter("m2"));
intm3=Integer.parseInt(req.getParameter("m3"));
Stringgrade=req.getParameter("grade");
pr.println("<html><bodybgcolor=yellowtext=red><divalign=center>");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connectioncon=DriverManager.getConnection("jdbc:odbc:ss");
//pr.println("Getconnection");
PreparedStatementpst=con.prepareStatement("Insertintostudatavalues(?,?,?,?,?,?,?,?)");
pst.setInt(1,id);
pst.setString(2,name);
5108 GTEC

29

IT9225 Internet Programming Lab

pst.setInt(3,age);
pst.setString(4,branch);
pst.setInt(5,m1);
pst.setInt(6,m2);
pst.setInt(7,m3);
pst.setString(8,grade);
pst.executeQuery();
con.commit();
pr.println("studentinformationaresuccessfullyregistered");
pr.println("<ahref=http://localhost:7001/student/main.html>gotomainpage</a>");
pr.println("</html></body>");
con.close();}
catch(SQLExceptione)
{
System.out.println(e.getMessage());}
catch(Exceptione){
e.printStackTrace();
}
}
};
Find3.Java
/*SEARCHTHEPARTICULARRECORD*/
importjavax.servlet.*;
importjavax.servlet.http.*;
importjava.io.*;
importjava.util.*;
importjava.sql.*;
importjava.lang.*;
publicclassfind3extendsHttpServlet{
publicvoiddoGet(HttpServletRequestreq,HttpServletResponseres)throws
ServletException,IOException{
res.setContentType("Text/html");
PrintWriterpr=res.getWriter();
pr.println("<html><bodybgcolor=blacktext=green><divalign=center>");
pr.println("<formaction=http://localhost:7001/student/find3method=post
name=form1>");
pr.println("<h4>EnterthestudentID:</h4><inputtype=textname=id>");
5108 GTEC

30

IT9225 Internet Programming Lab

pr.println("<h4>click:</h4><inputtype=submitname=submitvalue=search>");
pr.println("</form></div></body></html>");}
publicvoiddoPost(HttpServletRequestreq,HttpServletResponseres)throws
ServletException,IOException
{
try{
res.setContentType("Text/html");
PrintWriterpr=res.getWriter();
Stringid=req.getParameter("id");
intidno=Integer.parseInt(id);
pr.println("<html><bodybgcolor=blacktext=green><divalign=center>");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connectioncon=DriverManager.getConnection("jdbc:odbc:ss");
//PreparedStatementpst=con.prepareStatement("select*fromstudatawhereID='"+
idno+"'");
PreparedStatementpst=con.prepareStatement("select*fromstudatawhereID=?");
pst.setInt(1,idno);
ResultSetr=pst.executeQuery();
while(r.next()){
pr.println(r.getInt(1)+"\t"+r.getString(2)+"\t"+r.getInt(3)+"\t"+r.getSt
ring(4)+"\t"+r.getInt(5)+"\t"+r.getInt(6)+"\t"+r.getInt(7)+"\t"+r.getString(8));
pr.println("<br>");
}
pr.println("<ahref=http://localhost:7001/student/main.html>gotomainpage</a>");
pr.println("</html></body>");
}
catch(SQLExceptione){
System.out.println(e.getMessage());}
catch(Exceptione){
e.printStackTrace();
}
}
};
Delete2.java:
importjavax.servlet.*;
importjavax.servlet.http.*;
importjava.io.*;
5108 GTEC

31

IT9225 Internet Programming Lab

importjava.util.*;
importjava.sql.*;
importjava.lang.*;
publicclassdelete2extendsHttpServlet{
publicvoiddoPost(HttpServletRequestreq,HttpServletResponseres)throws
ServletException,IOException{
try{
res.setContentType("Text/html");
PrintWriterpr=res.getWriter();
pr.println("<html><bodybgcolor=blacktext=yellow>");
Stringidno=req.getParameter("idno");
intid=Integer.parseInt(idno);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connectioncon=DriverManager.getConnection("jdbc:odbc:ss");
pr.println("getconnected");
//PreparedStatementpst=con.prepareStatement("DeletefromstudatawhereID='"+id+
"'");
PreparedStatementpst=con.prepareStatement("DeletefromstudatawhereID=?");
pst.setInt(1,id);
pst.executeUpdate();
pr.println("<h2>studentrecordissuccessfullydeleted");
pr.println("<ahref=http://localhost:7001/student/main.html>gotomainpage</a>");
pr.println("</html></body>");con.commit();}
catch(SQLExceptione){
System.out.println(e.getMessage());}
catch(Exceptione){
e.printStackTrace();
}}
};
Output:
Studenttable:

5108 GTEC

32

IT9225 Internet Programming Lab

5108 GTEC

33

IT9225 Internet Programming Lab

5108 GTEC

34

IT9225 Internet Programming Lab

5108 GTEC

35

IT9225 Internet Programming Lab

Result:
Thusstudentinformationjavascriptprogramhasbeenexecutedandverifiedsuccessfully.

ExNo :07
5108 GTEC

WebCustomisation
36

IT9225 Internet Programming Lab

Date

Aim:
TocreateacalculatorwebapplicationusingPHP.

Algorithm:
Step1:Starttheprogram
Step2:Createaphpwebpagecalc.php
Step3:Usingformandinputtypetagcreatevariousbuttons,textbox,radiobuttonetc.
Step4:calcutetheoutputforvariousoption
Step5:Usingpostmethoddisplaytheresultinnextpage.
Step6:Stoptheprogram.

SourceCode:
Calc.php:
<?php
?>
<!DOCTYPEhtmlPUBLIC"//W3C//DTDXHTML1.0Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1strict.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Calculator</title>
</head>
<body>
<?php
//basiccalculatorprogram
functionshowForm(){
?>
Allfieldarerequired,however,ifyouforgetany,wewillputarandomnumberinforyou.
<br/>
<tableborder="0">
<formaction="<?phpecho$_SERVER['PHP_SELF'];?>"method="post">
<tr>
5108 GTEC

37

IT9225 Internet Programming Lab

<td>Number:</td>
<td><inputtype="text"maxlength="3"name="number"size="4"/>
</td>
</tr>
<spanid="square">
<tr>
<td>Anothernumber:</td>
<td><inputtype="text"maxlength="4"name="number2"size="4"/>
</td>
</tr>
</span>
<tr>
<tdvalign="top">Operator:</td>
<td>
<inputtype="radio"name="opt"value="+"</>+<br/>
<inputtype="radio"name="opt"value=""/><br/>
<inputtype="radio"name="opt"value="*"/>*<br/>
<inputtype="radio"name="opt"value="/"/>/<br/>
<inputtype="radio"name="opt"value="^2"/>x<sup>2</sup><br/>
<inputtype="radio"name="opt"value="sqrt"/>sqrt<br/>
<inputtype="radio"name="opt"value="^"/>^<br/>
</td>
</tr>
<tr>
<td>Rounding:</td>
<td>
<inputtype="text"name="rounding"value="4"size="4"maxlength="4"/></td>
<td>
<small>(Enterhowmanydigitsyouwouldliketoroundto)</small>
</td>
</tr>
<tr>
<td>
<inputtype="submit"value="Calculate"name="submit"/>
</td>
</tr>
</form>
</table>
5108 GTEC

38

IT9225 Internet Programming Lab

<?php
}
if(empty($_POST['submit'])){
showForm();
}else{
$errors=array();
$error=false;
if(!is_numeric($_POST['number'])){
(int)$_POST['number']=rand(1,200);
}
if(empty($_POST['number'])){
(int)$_POST['number']=rand(1,200);
}
if(!is_numeric($_POST['number2'])){
(int)$_POST['number2']=rand(1,200);
}
if(empty($_POST['number2'])){
(int)$_POST['number2']=rand(1,200);
}
if(empty($_POST['rounding'])){
$round=0;
}
if(!isset($_POST['opt'])){
$errors[]="Youmustselectanoperation.";
$error=true;
}
if(strpbrk($_POST['number'],"")andstrpbrk($_POST['number2'],"0.")and$_POST['opt']
=="^"){
$errors[]="Youcannotraiseanegativenumbertoadecimal,thisisimpossible.
<ahref=\"http://hudzilla.org/phpwiki/index.php?title=Other_mathematical_conv
ersion_functions\">Why?</a>";
$error=true;
}
if($error!=false){
echo"Wefoundtheseerrors:";
echo"<ul>";
foreach($errorsas$e){
echo"<li>$e</li>";
5108 GTEC

39

IT9225 Internet Programming Lab

}
echo"</ul>";
}else{
switch($_POST['opt']){case"+":$result=(int)strip_tags($_POST['number'])+
(int)strip_tags($_POST['number2']);
echo"Theanswerto".(int)strip_tags($_POST['number'])."$_POST[opt]".
(int)strip_tags($_POST['number2'])."is$result.";
break;
case"";
$result=(int)strip_tags($_POST['number'])(int)strip_tags($_POST['number2']);
echo"Theanswerto".(int)strip_tags($_POST['number'])."$_POST[opt]".
(int)strip_tags($_POST['number2'])."is$result.";
break;
case"*";
$result=(int)strip_tags($_POST['number'])*(int)strip_tags($_POST['number2']);echo"The
answerto".(int)strip_tags($_POST['number'])."$_POST[opt]".(int)$_POST['number2'].
"is$result.";
break;
case"/";
$result=(int)strip_tags($_POST['number'])/(int)strip_tags($_POST['number2']);$a=
ceil($result);
echo"<br/>";
echo"<hr/>";
echo"<h2>Rounding</h2>";
echo"$resultroundedupis$a";
echo"<br/>";
$b=floor($result);
echo"$resultroundeddownis$b";
echo"<br/>";
$h=round($result,(int)$_POST['rounding']);echo"$resultroundedto$_POST[rounding]
digitsis".$h;
break;
case"^2":
$result=(int)strip_tags($_POST['number'])*(int)strip_tags($_POST['number2']);$a=(int)
$_POST['number2']*(int)$_POST['number2'];
echo"Theanswerto".(int)$_POST['number']."<sup>2</sup>is".$result;
echo"<br/>";
5108 GTEC

40

IT9225 Internet Programming Lab

echo"Theanswerto".(int)$_POST['number2']."<sup>2</sup>is".$a;
break;
case"sqrt":
$result=(int)strip_tags(sqrt($_POST['number']));
$sqrt2=(int)strip_tags(sqrt($_POST['number2']));
echo"Thesquarerootof".(int)strip_tags($_POST['number'])."is".$result;echo"<br/>";
echo"Thesquarerootof".(int)strip_tags($_POST['number2'])."is".$sqrt2;echo"<br
/>";
echo"Thesquarerootof".(int)strip_tags($_POST['number'])."roundedto".
strip_tags($_POST[rounding])."digitsis".round($result,(int)$_POST['rounding']);
echo"<br/>";
echo"Thesquarerootof".(int)strip_tags($_POST['number2'])."roundedto".
strip_tags($_POST[rounding])."digitsis".round($sqrt2,
(int)strip_tags($_POST['rounding']));
break;
case"^":
$result=(int)strip_tags(pow($_POST['number'],$_POST['number2']));
$pow2=(int)strip_tags(pow($_POST['number2'],$_POST['number']));
echo(int)$_POST['number']."<sup>".strip_tags($_POST[number2])."</sup>is".
$result;
echo"<br/>";echo(int)$_POST['number2']."<sup>".strip_tags($_POST[number]).
"</sup>is".$pow2;
break;
}
}
}
echo"<br/>";
?>
<ahref="calc.php">GoBack</a>
</body>
</html>
Output:
calculatorwebapplication:

5108 GTEC

41

IT9225 Internet Programming Lab

5108 GTEC

42

IT9225 Internet Programming Lab

5108 GTEC

43

IT9225 Internet Programming Lab

Result:
Thus the calculator web application using PHP has been executed and verified
successfully.

ExNo :08
Date

5108 GTEC

DevelopmentofEBusinessApplication

44

IT9225 Internet Programming Lab

Aim:
TodevelopaEBusinessapplicationusingPHP.

Algorithm:
Step1:Starttheprogram
Step2:CreateaPHPwebpagecontact.php
Step3:Usingformandinputtypetagcreatevariousbuttons,textbox,radiobuttonetc.
Step4:Getthenecessaryfieldfromtheuser.
Step5:Usingpostmethoddisplaystheresultinnextpage.
Step6:Stoptheprogram.
SourceCode:
Contact.php
<!DOCTYPEhtmlPUBLIC"//W3C//DTDXHTML1.0Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1strict.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttpequiv="contenttype"content="text/html;charset=utf8"/><title>Weband
Crafts</title>
<metaname="keywords"content=""/>
<metaname="description"content=""/>
<linkhref="style.css"rel="stylesheet"type="text/css"media="screen"/>
</head>
<body><!#headerwrapper>
<?php$name=$_POST['name'];
$address=$_POST['address'];
$city=$_POST['city'];
$zip=$_POST['zip'];
$phonenumber=$_POST['phonenumber'];
$email=$_POST['email'];
$message=$_POST['message'];
$error=0;
if(isset($_POST['submit'])){
if(eregi('http:',$notes)){
die("DoNOTtrythat!!");
5108 GTEC

45

IT9225 Internet Programming Lab

}
if(!$email==""&&(!strstr($email,"@")||!strstr($email,".")))
{
echo"<h2>UseBackEntervalidemail</h2>\n";
$badinput="<h2>FeedbackwasNOTsubmitted</h2>\n";
echo$badinput;
$error=1;
}
if(empty($name)||empty($phonenumber)||empty($email)||empty($message))
{
echo"<h2>UseBackfillinallrequiredfields</h2>\n";
$error=1;
}
if($error!=1){
$todayis=date("l,Fj,Y,g:ia");
$attn=$subject;
$subject="mailfrom$email";
$message=stripcslashes($message);
$mailmessage="$todayis[EST]\nSubject:$subject\nMessage:$message\nFrom:
$name($email)\nCity:$city\nPin/Zipcode:$zip\nPhoneNo:$phonenumber\n";
$from="From:$email\r\n";
mail("[email protected]",$subject,$mailmessage,$from);
echo"ThankYou:";
echo"$name(";echo"$email)";
echo"foryourinterestinourservices.Wewillcontactyousoon<br>";
}
else{
echo"UseBackandFillallrequiredfields!!";
}
}
else
{
?>
<formaction="<?phpecho$_SERVER['PHP_SELF'];?>"method="post"
enctype="multipart/formdata"id="form1"><tablecellspacing="0"cellpadding="2"
width="100%"border="0"class="text_main">
<tr>
<tdalign="right"valign="center">
5108 GTEC

46

IT9225 Internet Programming Lab

<strong><fontcolor="#ff0000">*</font>&nbsp;Name:</strong>
</td>
<tdalign="left"valign="center">
<inputstyle="WIDTH:207px;HEIGHT:22px"size="26"name="name"/>
</td>
</tr>
<tr>
<tdalign="right"valign="center">
<strong>Address:</strong>
</td>
<tdalign="left"valign="center">
<textareastyle="WIDTH:205px;HEIGHT:80px"name="address"rows="6"cols="22">
</textarea>
</td>
</tr>
<tr>
<tdalign="right"valign="center">
<strong>City:</strong></td>
<tdalign="left"valign="center">
<inputstyle="WIDTH:205px;HEIGHT:22px"size="26"name="city"/>
</td></tr>
<tr>
<tdalign="right"valign="center">
<strong><fontcolor="#ff0000">*</font>&nbsp;PhoneNo:</strong></td>
<tdalign="left"valign="center"><inputstyle="WIDTH:168px;HEIGHT:22px"size="21"
name="phonenumber"/>
</td></tr>
<tr>
<tdalign="right"valign="center">
<strong><fontcolor="#ff0000">*</font>&nbsp;Email:</strong></td>
<tdalign="left"valign="center"><inputstyle="WIDTH:207px;HEIGHT:22px"size="26"
name="email"/>
</td></tr>
<tr>
<tdalign="right"valign="center">
<strong><fontcolor="#ff0000">*</font>&nbsp;YourMessage:</strong>
</td>
<tdalign="left"valign="center">
5108 GTEC

47

IT9225 Internet Programming Lab

<textareastyle="WIDTH:346px;HEIGHT:158px"name="message"rows="8"cols="37">
</textarea></td></tr>
<tr>
<tdvalign="center"align="right">
</td>
<tdvalign="center"align="left">
<inputtype="submit"value="Send"name="submit"/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<inputtype="reset"value="Clear"name="reset"/>
</td></tr>
<tr>
<tdvalign="center"align="right"></td>
<tdvalign="center"align="left"height="15"></td>
</tr>
<tr>
<tdalign="right"valign="center"></td>
<tdalign="left"valign="center">Fieldsmarked<fontcolor="#ff0000">*</font>are
mandatory</td>
</tr>
</table>
</form>
<?
Php
}
?>
</body>
</html>
Output:

5108 GTEC

48

IT9225 Internet Programming Lab

AboutUs.php:
<?php
5108 GTEC

49

IT9225 Internet Programming Lab

session_start();
?>
<!DOCTYPEhtmlPUBLIC"//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttpequiv="ContentType"content="text/html;charset=iso88591"/>
<title>EBookBizDemo</title>
<linkhref="css/stylesheet.css"type="text/css"rel="stylesheet"/>
</head>
<body>
<divid="wrapper">
<!headerstarts>
<?phpinclude_once'Header.php';?>
<!headerends>
<divid="content">
<p>
<br/>
<br/>
<br/>
<spanclass="font14b">
WeareanonlinestoresellingITandComputerrelatedbooks.Weservestudent
communityandofferspecialdiscountstostudents.<br/>
<br/>
ContactUsformoredetails</span></p>
<p><spanclass="font14b">EBookBiz<br/>
Tirupur<br/>
Phone:04214255202<br/>
email:[email protected]<br/>
<br/>
<br/>
RegistertodaytoShopforBooks!<br/>
<br/>
<br/>
</span>
</p>
</div>
<divid="footer">
5108 GTEC

50

IT9225 Internet Programming Lab

</div>
</div>
</body>
</html>
Order.php:
<?php
session_start();
include('Db.php');
if(!isset($_SESSION['ses_username']))
{
header("Location:Login.php");
}
$aOrderDetails=$_SESSION['orderdetails'];
?>
<!DOCTYPEhtmlPUBLIC"//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttpequiv="ContentType"content="text/html;charset=iso88591"/>
<title>EBookBizDemo</title>
<linkhref="css/stylesheet.css"type="text/css"rel="stylesheet"/>
</head>
<body>
<divid="wrapper">
<!headerstarts>
<?phpinclude_once'Header.php';
?>
<!headerends>
<divid="content">
SelectedBooks
<br/>
<br/>
<tablewidth="500"border="1"cellpadding="5"cellspacing="0">
<tr>
<tdwidth="43"align="center"valign="top"bgcolor="#FFFFCC">S.No</td>
<tdwidth="342"align="left"valign="top"bgcolor="#FFFFCC">BookTitle</td>
<tdwidth="77"align="left"valign="top"bgcolor="#FFFFCC">Price(Rs)</td>
5108 GTEC

51

IT9225 Internet Programming Lab

</tr>
<?php
$selectedBooks=$aOrderDetails['fSelectBook'];
$sno=1;
$total=0;
$numBooks=count($selectedBooks);
for($i=0;$i<$numBooks;$i++)
{
$query="SELECTid,title,priceFROMbooksWHEREid=".$selectedBooks[$i];
$result=mysql_query($query);
if($row=mysql_fetch_assoc($result))
{
$title=$row['title'];
$price=$row['price'];
$total+=$price;
?>
<tr>
<tdalign="left"valign="top"><?phpecho$sno;?></td>
<tdalign="left"valign="top"><?phpecho$title;?></td>
<tdalign="right"valign="top"><?phpecho$price;?></td>
</tr>
<?php
}
$sno++;
}
?>
<tr>
<tdcolspan="2"align="right"valign="top">TotalAmount(Rs)</td>
<tdalign="right"valign="top">
<?phpechonumber_format($total,2,'.',',');
?>
</td>
</tr>
</table>
</div>
<divid="footer"></div>
</div>
</body>
5108 GTEC

52

IT9225 Internet Programming Lab

</html>
DEPARTMENT.PHP:
<?php
session_start();
include('Db.php');
if(!isset($_SESSION['ses_username']))
{
header("Location:Login.php");
}
if(isset($_POST['seldept']))
{
header("Location:BookList.php?fDepartment=".$_POST['fDepartment']);
}
?>
<!DOCTYPEhtmlPUBLIC"//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttpequiv="ContentType"content="text/html;charset=iso88591"/>
<title>EBookBizDemo</title>
<linkhref="css/stylesheet.css"type="text/css"rel="stylesheet"/>
</head>
<body>
<divid="wrapper">
<!headerstarts>
<?php
include_once'Header.php';
?>
<!headerends>
<divid="content">
<br/>
<br/>
<br/>
<br/>
<formaction="<?phpecho$_SERVER['PHP_SELF'];?>"method="post"name="deptform">
<tablewidth="332"border="0"align="center"cellpadding="5"cellspacing="1"
class="tabBorder">
5108 GTEC

53

IT9225 Internet Programming Lab

<tr>
<tdcolspan="2"align="left"valign="top"bgcolor="#CCCCCC">&nbsp;</td>
</tr>
<tr>
<tdwidth="144"align="right"valign="top"bgcolor="#EAEAEA">ChoosetheDepartment
</td>
<tdwidth="168"align="left"valign="top"bgcolor="#EAEAEA"><label>
<selectname="fDepartment">
<option>SelectDepartment</option>
<optionvalue="1">ComputerScience</option>
<optionvalue="2">IT</option>
</select>
</label>
</td>
</tr>
<tr>
<tdcolspan="2"align="center"valign="top"bgcolor="#EAEAEA">
<label>
<inputtype="submit"name="seldept"value="ShowBookList"/>
</label></td>
</tr>
</table>
</form>
<br/>
<br/>
<br/>
<br/>
<br/>
<spanclass="font14b"></span>
</div>
<divid="footer">
</div>
</div>
</body>
</html>
BOOKLIST.PHP:
<?php
5108 GTEC

54

IT9225 Internet Programming Lab

session_start();
include('Db.php');
if(!isset($_SESSION['ses_username']))
{
header("Location:Login.php");
}
if(isset($_POST['fPlaceOrder']))
{
$_SESSION['orderdetails']=$_POST;header("Location:Order.php");
}
?>
<!DOCTYPEhtmlPUBLIC"//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttpequiv="ContentType"content="text/html;charset=iso88591"/>
<title>EBookBizDemo</title>
<linkhref="css/stylesheet.css"type="text/css"rel="stylesheet"/>
</head>
<body>
<divid="wrapper">
<!headerstarts>
<?phpinclude_once'Header.php';?>
<!headerends>
<divid="content">
<br/>
<br/>
<br/>
<br/>
<formaction="<?phpecho$_SERVER['PHP_SELF'];?>"method="post"
name="deptform">
<inputtype="hidden"name="fDepartment"value="<?phpecho
$_REQUEST['fDepartment'];?>"/>
<tablewidth="799"border="1"align="center"cellpadding="5"cellspacing="0">
<tr>
<tdwidth="39"align="center"valign="top"bgcolor="#FFFFCC">S.No</td>
<tdwidth="394"align="left"valign="top"bgcolor="#FFFFCC">BookTitle</td>
<tdwidth="154"align="left"valign="top"bgcolor="#FFFFCC">AuthorName</td>
5108 GTEC

55

IT9225 Internet Programming Lab

<tdwidth="72"align="left"valign="top"bgcolor="#FFFFCC">Price</td>
<tdwidth="78"align="center"valign="top"bgcolor="#FFFFCC">AddtoCart</td>
</tr>
<?php
$dept=$_GET['fDepartment'];
$query="SELECTid,title,authorname,price,departmentFROMbooksWHERE
department=".$dept;
$result=mysql_query($query,$con);
$i=1;
while($row=mysql_fetch_assoc($result))
{
?>
<tr>
<tdalign="center"valign="top"><?phpecho$i;?></td>
<tdalign="left"valign="top"><?phpecho$row['title'];?></td>
<tdalign="left"valign="top"><?phpecho$row['authorname'];?></td>
<tdalign="left"valign="top">Rs.<?phpecho$row['price'];?></td>
<tdalign="center"valign="top">
<inputtype="checkbox"name="fSelectBook[]"value="<?phpecho$row['id'];?>"/>
</td>
</tr>
<?php
$i=$i+1;
}
?>
</table>
<br/>
<br/>
<divstyle="textalign:center;">
<inputtype="submit"name="fPlaceOrder"value="PlaceOrder"/>
</div>
</form>
<br/>
<br/>
<br/>
<br/>
<br/>
<spanclass="font14b">
5108 GTEC

56

IT9225 Internet Programming Lab

</span>
</div><divid="footer">
</div>
</div>
</body>
</html>
Db.php:
<?php
$db_hostname='localhost';
$db_dbname='ebookbiz';
$db_username='root';
$db_password='';
$con=mysql_pconnect($db_hostname,$db_username,$db_password);
mysql_select_db($db_dbname,$con);?>
Header.php:
<divid="header">
<divid="logo">
<spanclass="logoStyle">EBOOKBIZ</span>
</div>
<divid="navigation">
<ahref="index.php"class="navLink">Home</a>&nbsp;&nbsp;&nbsp;&nbsp;|
&nbsp;&nbsp;&nbsp;&nbsp;
<ahref="Login.php"class="navLink">Login</a>&nbsp;&nbsp;&nbsp;&nbsp;|
&nbsp;&nbsp;&nbsp;&nbsp;
<ahref="Department.php"
class="navLink">Department</a>&nbsp;&nbsp;&nbsp;&nbsp;|
&nbsp;&nbsp;&nbsp;&nbsp;
<ahref="Feedback.php"class="navLink">Feedback</a>
</div>
<divstyle="textalign:right;fontfamily:'TrebuchetMS';fontsize:12px;fontweight:bold;">
<?php
if(isset($_SESSION['ses_username']))
{
echo'Welcome'.$_SESSION['ses_username'];
echo'&nbsp;|&nbsp;<ahref="Logout.php"class="navLink">Logout</a>';
}
5108 GTEC

57

IT9225 Internet Programming Lab

?>
</div>
</div>
Index.php:
<?
phpsession_start();
?>
<!DOCTYPEhtmlPUBLIC"//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttpequiv="ContentType"content="text/html;charset=iso88591"/>
<title>EBookBizDemo</title>
<linkhref="css/stylesheet.css"type="text/css"rel="stylesheet"/>
</head>
<body>
<divid="wrapper">
<!headerstarts>
<?phpinclude_once'Header.php';?>
<!headerends>
<divid="content">
<br/>
<br/>
<br/>
<spanclass="font14b">
InformationTechnologyandComputerScienceBooks.
<br/>
<br/>
<br/>
LowPriceeditionsatdiscounttostudentsofUGandPGcourses.
<br/>
<br/>
<br/>
RegistertodaytoShopforBooks!
<br/>
<br/>
<br/>
5108 GTEC

58

IT9225 Internet Programming Lab

</span>
</div>
<divid="footer">
</div>
</div>
</body>
</html>
<?php
session_start();
include('Db.php');
if(isset($_POST['Submit']))
{
$login_id=$_POST['fLoginId'];
$password=$_POST['fPassword'];
$query="SELECTusernameFROMusersWHERElogin_id='".$login_id."'AND
password='".$password."'";
$result=mysql_query($query,$con);
if($result){while($row=mysql_fetch_assoc($result))
{
$userName=$row['username'];
}
$_SESSION['ses_username']=$userName;
header("Location:Department.php");
}
else
{
$resultmsg="Pleaseprovidecorrectloginidandpassword";
}
}
?>
<!DOCTYPEhtmlPUBLIC"//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttpequiv="ContentType"content="text/html;charset=iso88591"/>
<title>EBookBizDemo</title>
<linkhref="css/stylesheet.css"type="text/css"rel="stylesheet"/>
</head>
5108 GTEC

59

IT9225 Internet Programming Lab

<body>
<divid="wrapper">
<!headerstarts>
<?php
include_once'Header.php';?>
<!headerends>
<divid="content">
<br/>
<br/>
<br/>
<br/>
<div>
<?php
if(isset($resultmsg))
{
echo$resultmsg;
}
?>
</div>
<formaction="<?phpecho$_SERVER['PHP_SELF'];?>"method="post"
name="loginform">
<tablewidth="332"border="0"align="center"cellpadding="5"cellspacing="1"
class="tabBorder">
<tr>
<tdcolspan="2"align="left"valign="top"bgcolor="#CCCCCC">Login</td>
</tr>
<tr>
<tdwidth="144"align="right"valign="top"bgcolor="#EAEAEA">LoginID</td>
<tdwidth="168"align="left"valign="top"bgcolor="#EAEAEA">
<label>
<inputtype="text"name="fLoginId"/></label></td>
</tr>
<tr>
<tdalign="right"valign="top"bgcolor="#EAEAEA">Password</td>
<tdalign="left"valign="top"bgcolor="#EAEAEA"><inputtype="password"
name="fPassword"/>
</td>
</tr>
5108 GTEC

60

IT9225 Internet Programming Lab

<tr>
<tdcolspan="2"align="center"valign="top"bgcolor="#ECECEC">
<label>
<inputname="Submit"type="submit"value="Login"/>
</label>
</td>
</tr>
<tr>
<tdcolspan="2"align="left"valign="top"bgcolor="#ECECEC">
<ahref="Registration.php"class="navLink">NewUser?Register</a>
</td>
</tr>
</table>
</form>
<br/>
<br/>
<br/>
<br/>
<br/>
<spanclass="font14b">
</span>
</div>
<divid="footer">
</div>
</div>
</body>
</html>
Logout.php:
<?php
session_start();
session_destroy();
header("Location:index.php");
?>
Registration.php:
<?php
session_start();
include('Db.php');
5108 GTEC

61

IT9225 Internet Programming Lab

if(!empty($_REQUEST['Submit']))
{
//echo'formsubmittedforregistration...';
$name=$_POST['fName'];
$address1=$_POST['fAddress1'];
$address2=$_POST['fAddress2'];
$city=$_POST['fCity'];
$state=$_POST['fState'];
$pincode=$_POST['fPincode'];
$phone=$_POST['fPhone'];
$email=$_POST['fEmail'];
$login_id=$_POST['fLoginId'];
$password=$_POST['fPassword'];
$query="INSERTINTOusers(id,username,address1,address2,city,state,pincode,
phone,email,login_id,password)VALUES(null,'{$name}','{$address1}','{$address2}',
'{$city}','{$state}','{$pincode}','{$phone}','{$email}','{$login_id}','{$password}')";
mysql_query($query,$con);
$msg='Registrationsuccessful.';
header("Location:Login.php?msg=success");
}
?>
<!DOCTYPEhtmlPUBLIC"//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttpequiv="ContentType"content="text/html;charset=iso88591"/>
<title>EBookBizDemo</title>
<linkhref="css/stylesheet.css"type="text/css"rel="stylesheet"/>
<script>
functionvalidate()
{
alert("ssssssssssssss");
varfrm=document.forms['regform'];
if(document.regform.fName.value=='')
{
alert("PleaseenteryourName)";
returnfalse;
}
5108 GTEC

62

IT9225 Internet Programming Lab

if(frm.fEmail.value=='')
{
alert("PleaseenteryourEmail");
returnfalse;
}
if(frm.fLoginId.value=='')
{
alert("PleaseenteryourLoginId");
returnfalse;
}
if(frm.fPassword.value=='')
{
alert("PleaseenteryourPassword");
returnfalse;
}
}
</script>
</head>
<body>
<divid="wrapper">
<!headerstarts>
<?php
include_once'Header.php';
?>
<!headerends>
<divid="content">
<br/>
<br/>
<br/>
<br/>
<div>
<?php
if(isset($msg))
{
//echo$msg;
}
?>
</div>
5108 GTEC

63

IT9225 Internet Programming Lab

<formaction="<?phpecho$_SERVER['PHP_SELF'];?>"method="post"name="regform"
onsubmit="returnvalidate();">
<tablewidth="332"border="0"align="center"cellpadding="5"cellspacing="1"
class="tabBorder">
<tr>
<tdcolspan="2"align="left"valign="top"bgcolor="#CCCCCC">Registration</td>
</tr>
<tr>
<tdwidth="144"align="right"valign="top"bgcolor="#EAEAEA">Name<em>*</em>
</td>
<tdwidth="168"align="left"valign="top"bgcolor="#EAEAEA">
<inputname="fName"type="text"id="fName"/>
</td>
</tr>
<tr>
<tdwidth="144"align="right"valign="top"bgcolor="#EAEAEA">Address1</td>
<tdwidth="168"align="left"valign="top"bgcolor="#EAEAEA">
<inputname="fAddress1"type="text"id="fAddress1"/>
</td>
</tr>
<tr>
<tdwidth="144"align="right"valign="top"bgcolor="#EAEAEA">Address2</td>
<tdwidth="168"align="left"valign="top"bgcolor="#EAEAEA">
<inputname="fAddress2"type="text"id="fAddress2"/>
</td>
</tr>
<tr>
<tdwidth="144"align="right"valign="top"bgcolor="#EAEAEA">City</td>
<tdwidth="168"align="left"valign="top"bgcolor="#EAEAEA">
<inputname="fCity"type="text"id="fCity"/>
</td>
</tr>
<tr>
<tdwidth="144"align="right"valign="top"bgcolor="#EAEAEA">State</td>
<tdwidth="168"align="left"valign="top"bgcolor="#EAEAEA">
<inputname="fState"type="text"id="fState"/>
</td>
</tr>
5108 GTEC

64

IT9225 Internet Programming Lab

<tr>
<tdwidth="144"align="right"valign="top"bgcolor="#EAEAEA">Pincode</td>
<tdwidth="168"align="left"valign="top"bgcolor="#EAEAEA">
<inputname="fPincode"type="text"id="fPincode"/>
</td>
</tr>
<tr>
<tdwidth="144"align="right"valign="top"bgcolor="#EAEAEA">PhoneNumber</td>
<tdwidth="168"align="left"valign="top"bgcolor="#EAEAEA">
<inputname="fPhone"type="text"id="fPhone"/>
</td>
</tr>
<tr>
<tdwidth="144"align="right"valign="top"bgcolor="#EAEAEA">EmailID<em>*</em>
</td>
<tdwidth="168"align="left"valign="top"bgcolor="#EAEAEA">
<inputname="fEmail"type="text"id="fEmail"/>
</td>
</tr>
<tr>
<tdheight="15"colspan="2"align="right"valign="top"bgcolor="#EAEAEA"></td>
</tr>
<tr>
<tdwidth="144"align="right"valign="top"bgcolor="#EAEAEA">LoginID<em>*</em>
</td>
<tdwidth="168"align="left"valign="top"bgcolor="#EAEAEA">
<inputname="fLoginId"type="text"id="fLoginId"/>
</td>
</tr>
<tr>
<tdwidth="144"align="right"valign="top"bgcolor="#EAEAEA">Password<em>*</em>
</td>
<tdwidth="168"align="left"valign="top"bgcolor="#EAEAEA">
<inputname="fPassword"type="password"id="fPassword"/>
</td>
</tr>
<tr>
<tdcolspan="2"align="center"valign="top"bgcolor="#EAEAEA">
5108 GTEC

65

IT9225 Internet Programming Lab

<label>
<inputtype="submit"name="Submit"value="Submit"/>
</label>
</td>
</tr>
</table>
</form>
<br/>
<br/>
<br/>
<br/>
<br/>
<spanclass="font14b">
</span>
</div>
<divid="footer">
</div>
</div>
</body>
</html>
STYLESHEET:
#wrapper
{
margin:auto;
width:980px;
minheight:600px;
fontfamily:Arial,Helvetica,sansserif;
fontsize:12px;
color:#333333;
borderleft:#3333331pxsolid;
borderright:#3333331pxsolid;
bordertop:#3333331pxsolid;
borderbottom:#3333331pxsolid;
padding:5px5px5px5px;
}
#header{
width:980px;
5108 GTEC

66

IT9225 Internet Programming Lab

height:70px;
borderbottom:#6600001pxdotted;
}
#content{
width:980px;
padding:10px10px10px10px;
}
.logoStyle{
fontfamily:"TrebuchetMS";
fontsize:24px;
fontweight:bold;
color:#660000;
}
#navigation{
paddingtop:10px;
}.navLink
{
fontfamily:Verdana,Arial,Helvetica,sansserif;
fontsize:12px;
fontweight:bold;
color:#333300;
textdecoration:none;
}
.navLink:hover{
fontfamily:Verdana,Arial,Helvetica,sansserif;
fontsize:12px;
fontweight:bold;
color:#009900;
textdecoration:underline;
}
.font14b{
fontfamily:Verdana,Arial,Helvetica,sansserif;
fontsize:14px;
fontweight:bold;
color:#000000;
}
.tabBorder{
borderbottom:#0000001pxsolid;
5108 GTEC

67

IT9225 Internet Programming Lab

borderleft:#0000001pxsolid;
bordertop:#0000001pxsolid;
borderright:#0000001pxsolid;
}

Output:
AboutUs.php:

Login.php:
5108 GTEC

68

IT9225 Internet Programming Lab

RegistrationFrom.php:

Department.php:
5108 GTEC

69

IT9225 Internet Programming Lab

BookList.php:

Order.php:
5108 GTEC

70

IT9225 Internet Programming Lab

Result:
ThustheEBusinessApplicationusingPHPhasbeenexecutedandverifiedsuccessfully.

5108 GTEC

71

IT9225 Internet Programming Lab

You might also like