0% found this document useful (0 votes)
627 views

Webtech Lab Manual

The document contains a lab manual for a Web Technology lab at Sasurie College of Engineering. It includes topics like designing web pages using client-side scripting and DHTML, client-server scripting programs, simulation of email and file transfer protocols, development of web services using XML and databases, and developing e-business applications. The document provides algorithms and program code for examples on client-side scripting, client-server programs, and simulating file transfer between a client and server.

Uploaded by

Abinaya Janani
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
627 views

Webtech Lab Manual

The document contains a lab manual for a Web Technology lab at Sasurie College of Engineering. It includes topics like designing web pages using client-side scripting and DHTML, client-server scripting programs, simulation of email and file transfer protocols, development of web services using XML and databases, and developing e-business applications. The document provides algorithms and program code for examples on client-side scripting, client-server programs, and simulating file transfer between a client and server.

Uploaded by

Abinaya Janani
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 86

SASURIE COLLEGE OF ENGINEERING VIJAYAMANGALAM

DEPARTMENT OF INFORMATION TECHNOLOGY


LAB MANUAL

WEB TECHNOLOGY LAB M.TECH(II SEMESTER)

PREPARED BY P.MURUGA PRIYA (LECTURER / IT)

CS9228 WEB TECHNOLOGY LABORATORY

S.N o
1

TOPIC
Designing Web Pages using Client Side Scripting and DHTML.

PAGE NO.

2 3 4 5 6 7 8

Client Server Scripting Programs. Simulation of Email and File Transfer Protocols. Development of Web Services. XML and Databases. Server Side Application Using JSP. Web Customization. Development of E-Business Application.

CS9228 WEB TECHNOLOGY LABORATORY


1. Designing Web Pages using Client Side Scripting and DHTML. Aim : To design a Web Page using Client Side Scripting and DHTML. Algorithm : 1.Start the program 2.The form will include text fields called "First Name", last Name,Address etc 3. Validation script will ensure that the user enters their name before the form is sent to the server. 4. Open this page to see it in action. 5. Try pressing the Place Order button without filling anything field will return null order 6. You might like to open the source code for this form in a separate window the page consists of a JavaScript function called validate_form() that performs the form validation, followed by the form itself. Program: <html> <head> <script type="text/javascript"> function blinking_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 { document.getElementById('blink').style.color="red"; }

timer=setTimeout("blinking_header()",100); } function stoptimer() { clearTimeout(timer); } </script> </head> <body onload="blinking_header()" onunload="stoptimer()"> <h1 id="blink">Blinking header</h1> <form name="OrderForm"> <table border=2 width="75%"> <tr> <td> <i>First Name</i> </td> <td> <input type="text" name="Firstname" size=30 onfocus="window.status='Enter ur firstname please'"> </td> </tr> <tr> <td> <i>Last Name</i> </td> <td> <input type="text" name="lastname" size=30 onfocus="window.status='Enter ur lastname please'"> </td> </tr> <tr> <td> <i>Address<i> </td> <td colspan="3"> <input type="text" name="address" size=30 onfocus="window.status='Enter ur mailungaddress please'"> </td> </tr> <tr> <td> <i>City</i> </td> <td>

<input type="text" name="city" size=30 onfocus="window.status='Enter ur city please'"> </td> </tr> <tr> <td> <i>State</i> </td> <td> <input type="text" name="state" size=30 onfocus="window.status='Enter ur state please'"> </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> would u like to be in ur mailing list <input type="checkbox" name="list" checked onclick="notify()">Yes </center> <p> <hr widh=50% align=center> <p> <select name="orderitem"> <option value="8.95">Grey <option value="12.95">Color <option value="24.99">Our Mid Range Item <option value="99.95">Super Deluxe </select> Select the Item u want <p> <select name="Qty"> <option value="1">One <option value="2">Two <option value="3">Three <option value="4">Four </select>Select the qty of items to order</b>

<p> Total Due <input type=text name="total" size=11 onfocus="totalorder(this.form)"> <hr> <p> <input type=submit value="Place order" ><input type=reset value="clear the form"> </form> <script language="javascript"> function notify() { alert("Please be aware that mailing list is for internal use"); } function totalorder(form) { var x=form.orderitem.options[form.orderitem.selectedIndex].value; var y=form.Qty.options[form.Qty.selectedIndex].value; var due=x*y; form.total.value=due; } </script> </body> </html>

Ex No: 2. Aim :

CLIENT SERVER SCRIPTING PROGRAMS.

To develop a simple Client Server Scripting Programs in a single web

page.
Algorithm:

1.Start the program 2. Create a server variable, MyServerVar, and a client variable, MyClientVar. 3. It prints simple text strings to identify each value. 4.The server code marked with the server script tags, <% %> and the client script shown with <SCRIPT> tags. 5.Stop the program. Program : Server Scripting Program :
<%@ LANGUAGE="VBSCRIPT" %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0"> <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1"> <TITLE>Sample Script Evaluation</TITLE> </HEAD> <BODY> <-- *** Server Script *** ---> <% MyServerVar = 6 %> <P>This value was evaluated on the server " <% MyServerVar %>"</P> <-- *** Client Script with a Server Script Variable *** ---> <SCRIPT LANGUAGE="jscript"> <!--var MyClientVar ; MyClientVar = (<%= MyServerVar %> + 1) ; document.write ('<P>This value is a client value ' + MyClientVar + '</P>'); if(MyClientVar == 42) { document.write ('<P>The server and client values are equal ' + MyClientVar + '</P>'); } else { document.write ("<P>The server and client value are not equal because our script told the client to add 1.</P>"); } // ---> </SCRIPT> </BODY> </HTML>

Client scripting program :


<HTML> <HEAD><META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0"> <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1"> <TITLE>Sample Script Evaluation</TITLE> </HEAD> <BODY> <-- *** Server Script was here *** ---> <P>This value was evaluated on the server 6</P> <-- *** Client Script is here with the Value from the Server Variable *** ---> <SCRIPT LANGUAGE="jscript"> <!--var MyClientVar ; MyClientVar = (6 + 1) ; document.write ('<P>This value is a client value ' + MyClientVar + '</P>'); if(MyClientVar == 42) { document.write ('<P>The server and client values are equal: ' + MyClientVar + '</P>'); } else { document.write ("<P>The server and client value are not equal because our script told the client to add 1.</P>"); } // ---> </SCRIPT> </BODY> </HTML>

Output :

Ex No.3.

Simulation of Email and File Transfer Protocols.

AIM:

To write a C program for transferring a file using TCP.

ALGORITHM:
SERVER: Step 1:Start the program. Step 2:Create an unnamed socket for the server using parameters AF_INET as domain and SOCK_STREAM as type. Step 3:Get the server port number. Step 4:Register the host address to the system by using bind() system call in server side. Step 5:Create a connection queue and wait for clients using listen() system call with the number of clients requests as parameter. Step 6:Create a Child process using fork( ) system call. Step 7:If the process identification number is equal to zero accept the connection using accept( ) system call when the client request for connection. Step 8:If pid is not equal to zero then exit the process. Step 9:Stop the Program execution. CLIENT: Step 1:Start the program. Step 2:Create an unnamed socket for the client using parameters AF_INET as domain and SOCK_STREAM as type. Step 3:Get the client port number. Step 4:Now connect the socket to server using connect( ) system call. Step 5:Enter the file name. Step 6:The file is transferred from client to server using send ( ) function. Step 7:Print the contents of the file in a new file. Step 8:Stop the program.

SERVER

#include<stdio.h> #include<sys/types.h> #include<netinet/in.h> #include<string.h> main() { FILE *fp; int sd,newsd,ser,n,a,cli,pid,bd,port,clilen; char name[100],fileread[100],fname[100],ch,file[100],rcv[100]; struct sockaddr_in servaddr,cliaddr; printf("Enter the port address: "); scanf("%d",&port); sd=socket(AF_INET,SOCK_STREAM,0); if(sd<0) printf("Can't Create \n"); else printf("Socket is Created\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,(struct sockaddr*)&servaddr,a); if(bd<0) printf(" Can't Bind\n"); else printf("\n Binded\n"); listen(sd,5); clilen=sizeof(cliaddr); newsd=accept(sd,(struct sockaddr*)&cliaddr,&clilen); if(newsd<0) printf("Can't Accept\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 { while(fgets(fileread,sizeof(fileread),fp))

{ if(send(newsd,fileread,sizeof(fileread),0)<0) { printf("Can't send\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; int csd,n,ser,s,cli,cport,newsd; char name[100],rcvmsg[100],rcvg[100],fname[100]; struct sockaddr_in servaddr; printf("Enter the port"); scanf("%d",&cport); csd=socket(AF_INET,SOCK_STREAM,0); if(csd<0) { printf("Error..."); exit(0); } else printf("Socket is Created...\n");

servaddr.sin_family=AF_INET; servaddr.sin_addr.s_addr=htonl(INADDR_ANY);servaddr.sin_port=htons(cport); if(connect(csd,(struct sockaddr*)&servaddr,sizeof(servaddr))<0) printf("Error in Connection...\n"); else printf("Connected...\n"); printf("Enter the existing file name: "); scanf("%s",name); printf("\nEnter the new filename: "); 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("File is not Available...\n"); if(strcmp(rcvg,"completed")==0) { printf("file is transferred...\n"); fclose(fp); close(csd); break; } else fputs(rcvg,stdout); fprintf(fp,"%s",rcvg); } }

OUTPUT:

Server Side [1me16@localhost ~]$ cc ftpclient.c [1me16@localhost ~]$. /a.out Enter the port address: 8663 Socket is Created Binded Connected Client Side [1me16@localhost ~]$ cc ftpserver.c [1me16@localhost ~]$. /a.out Socket is Created.. Connected Enter the existing file name: net

Enter the new file name: network Welcome to Network Lab File is transferred...

RESULT

Thus the C program for transferring file from one machine to another machine using TCP is executed and the output is verified successfully.

EMAIL
#include <stdlib.h> #include <string.h> #define cknull(x) if((x)==NULL) {perror(""); exit(EXIT_FAILURE);} #define cknltz(x) if((x)<0) {perror(""); exit(EXIT_FAILURE);} #define LIST_LEN 4 //char *f="sam.txt"; void email_it(char *filename); main() { char fname[15]; printf("enter the filename\n"); scanf("%s",fname); email_it(fname); } void email_it(char *filename) { char tmp[256]={0x0}; char fpBuffer[400]={0x0}; char email_list[LIST_LEN][256]={{"[email protected]"},{0x0}}; int i=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)); if(system (fpBuffer)==(-1)) { perror("email failure"); exit(EXIT_FAILURE); } } }

OUTPUT:

[1me2@localhost ~]$ vi email.c [1me2@localhost ~]$ cc email.c [1me2@localhost ~]$ ./a.out Enter the file name: sample.c [1me2@localhost ~]$/home/1me1/dead.letter.saved message in /home/1me1/dead.letter..

RESULT

Thus the program for developing E-mail application is executed and the output is verified successfully.

Ex No :4 Aim :

Development of Web Services

To develop a web service program for calculating Factorial of a number. Algorithm : Start the program. Give one parameter name x Data type as int Click on ok This will create the Web Service code with the name as factorial and method name as fact1 6. This will be having the annotation as @Webservice ,@Webmethod and @Webparam 7. Stop the program
1. 2. 3. 4. 5.

Program : package pack1; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; @WebService() public class factorial { int fact=1; @WebMethod(operationName = "fact1") public String fact1(@WebParam(name = "x") int x) { for (int y=1;y<=x;y++){ fact=fact*y; } return "factorial of "+x +" is "+fact; } } package pack1;

public class Client1 { public static void main(String[] args) { try { pack1.FactorialService service = new pack1.FactorialService(); pack1.Factorial port = service.getFactorialPort(); int x = 5; java.lang.String result = port.fact1(x); System.out.println("Result = "+result); } catch (Exception ex) { ex.printStackTrace(); } } }

Output :

Ex No :5 XML and Databases.

PARSING AN XML DOCUMENT USING DOM AND SAX PARSERS. AIM: To Parsing an XML document using DOM and SAX Parsers. ALGORITHM : Using Dom: Step1: Get a document builder using document builder factory and parse the xml file to create a DOM object Step 2: Get a list of employee elements from the DOM Step3: For each employee element get the id, name, age and type. Create an employee value object and add it to the list. Step4: At the end iterate through the list and print the employees to verify we parsed it right. Using Sax Step1: Create a Sax parser and parse the xml Step2: In the event handler create the employee object Step3 : Print out the data Coding employees.xml <?xml version="1.0" encoding="UTF-8"?> <Personnel> <Employee type="permanent"> <Name>Seagull</Name> <Id>3674</Id> <Age>34</Age> </Employee> <Employee type="contract"> <Name>Robin</Name> <Id>3675</Id> <Age>25</Age> </Employee> <Employee type="permanent"> <Name>Crow</Name> <Id>3676</Id> <Age>28</Age> </Employee> </Personnel> Using DOM

DomParserExample.java a) Getting a document builder private void parseXmlFile(){ //get the factory DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { //Using factory get an instance of document builder DocumentBuilder db = dbf.newDocumentBuilder(); //parse using builder to get DOM representation of the XML file dom = db.parse("employees.xml"); }catch(ParserConfigurationException pce) { pce.printStackTrace(); }catch(SAXException se) { se.printStackTrace(); }catch(IOException ioe) { ioe.printStackTrace(); } } b) Get a list of employee elements Get the rootElement from the DOM object.From the root element get all employee elements. Iterate through each employee element to load the data. private void parseDocument(){ //get the root element Element docEle = dom.getDocumentElement(); //get a nodelist of elements NodeList nl = docEle.getElementsByTagName("Employee"); if(nl != null && nl.getLength() > 0) { for(int i = 0 ; i < nl.getLength();i++) { //get the employee element Element el = (Element)nl.item(i); //get the Employee object Employee e = getEmployee(el); //add it to list myEmpls.add(e); } } } c) Reading in data from each employee. /** * I take an employee element and read the values in, create * an Employee object and return it */ private Employee getEmployee(Element empEl) {

//for each <employee> element get text or int values of //name ,id, age and name String name = getTextValue(empEl,"Name"); int id = getIntValue(empEl,"Id"); int age = getIntValue(empEl,"Age"); String type = empEl.getAttribute("type"); //Create a new Employee with the value read from the xml nodes Employee e = new Employee(name,id,age,type); return e; } /** * I take a xml element and the tag name, look for the tag and get * the text content * i.e for <employee><name>John</name></employee> xml snippet if * the Element points to employee node and tagName is 'name' I will return John */ private String getTextValue(Element ele, String tagName) { String textVal = null; NodeList nl = ele.getElementsByTagName(tagName); if(nl != null && nl.getLength() > 0) { Element el = (Element)nl.item(0); textVal = el.getFirstChild().getNodeValue(); } return textVal; } /** * Calls getTextValue and returns a int value */ private int getIntValue(Element ele, String tagName) { //in production application you would catch the exception return Integer.parseInt(getTextValue(ele,tagName)); } d) Iterating and printing. private void printData(){ System.out.println("No of Employees '" + myEmpls.size() + "'."); Iterator it = myEmpls.iterator(); while(it.hasNext()) { System.out.println(it.next().toString()); } } Using Sax: SAXParserExample.java a) Create a Sax Parser and parse the xml

private void parseDocument() { //get a factory SAXParserFactory spf = SAXParserFactory.newInstance(); try { //get a new instance of parser SAXParser sp = spf.newSAXParser(); //parse the file and also register this class for call backs sp.parse("employees.xml", this); }catch(SAXException se) { se.printStackTrace(); }catch(ParserConfigurationException pce) { pce.printStackTrace(); }catch (IOException ie) { ie.printStackTrace(); } } b) In the event handlers create the Employee object and call the corresponding setter methods. //Event Handlers public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { //reset tempVal = ""; if(qName.equalsIgnoreCase("Employee")) { //create a new instance of employee tempEmp = new Employee(); tempEmp.setType(attributes.getValue("type")); } } public void characters(char[] ch, int start, int length) throws SAXException { tempVal = new String(ch,start,length); } public void endElement(String uri, String localName, String qName) throws SAXException { if(qName.equalsIgnoreCase("Employee")) { //add it to the list myEmpls.add(tempEmp); }else if (qName.equalsIgnoreCase("Name")) { tempEmp.setName(tempVal); }else if (qName.equalsIgnoreCase("Id")) { tempEmp.setId(Integer.parseInt(tempVal)); }else if (qName.equalsIgnoreCase("Age")) { tempEmp.setAge(Integer.parseInt(tempVal)); }

} c) Iterating and printing. private void printData(){ System.out.println("No of Employees '" + myEmpls.size() + "'."); Iterator it = myEmpls.iterator(); while(it.hasNext()) { System.out.println(it.next().toString()); } } OUTPUT: Employee Details - Name:Seagull, Type:permanent, Id:3674, Age:34. Employee Details - Name:Robin, Type:contract, Id:3675, Age:25. Employee Details - Name:Crow, Type:permanent, Id:3676, Age:28. Result : Thus the Parsing an XML document using DOM and SAX Parsers is been done and executed successfully.

CREATION PARSING AN XML DOCUMENT USING DOM AND SAX PARSERS. AIM: To Parsing an XML document using DOM and SAX Parsers. ALGORITHM: Using Dom: Step1: Get a document builder using document builder factory and parse the xml file to create a DOM object Step 2: Get a list of employee elements from the DOM Step3: For each employee element get the id, name, age and type. Create an employee value object and add it to the list. Step4: At the end iterate through the list and print the employees to verify we parsed it right. Using Sax Step1: Create a Sax parser and parse the xml Step2: In the event handler create the employee object Step3 : Print out the data Coding employees.xml <?xml version="1.0" encoding="UTF-8"?> <Personnel> <Employee type="permanent"> <Name>Seagull</Name> <Id>3674</Id> <Age>34</Age> </Employee> <Employee type="contract"> <Name>Robin</Name> <Id>3675</Id> <Age>25</Age> </Employee> <Employee type="permanent"> <Name>Crow</Name> <Id>3676</Id> <Age>28</Age> </Employee> </Personnel> Using DOM DomParserExample.java a) Getting a document builder private void parseXmlFile(){ //get the factory DocumentBuilderFactory dbf =

DocumentBuilderFactory.newInstance(); try { //Using factory get an instance of document builder DocumentBuilder db = dbf.newDocumentBuilder(); //parse using builder to get DOM representation of the XML file dom = db.parse("employees.xml"); }catch(ParserConfigurationException pce) { pce.printStackTrace(); }catch(SAXException se) { se.printStackTrace(); }catch(IOException ioe) { ioe.printStackTrace(); } } b) Get a list of employee elements Get the rootElement from the DOM object.From the root element get all employee elements. Iterate through each employee element to load the data. private void parseDocument(){ //get the root element Element docEle = dom.getDocumentElement(); //get a nodelist of elements NodeList nl = docEle.getElementsByTagName("Employee"); if(nl != null && nl.getLength() > 0) { for(int i = 0 ; i < nl.getLength();i++) { //get the employee element Element el = (Element)nl.item(i); //get the Employee object Employee e = getEmployee(el); //add it to list myEmpls.add(e); } } } c) Reading in data from each employee. /** * I take an employee element and read the values in, create * an Employee object and return it */ private Employee getEmployee(Element empEl) { //for each <employee> element get text or int values of //name ,id, age and name String name = getTextValue(empEl,"Name"); int id = getIntValue(empEl,"Id"); int age = getIntValue(empEl,"Age");

String type = empEl.getAttribute("type"); //Create a new Employee with the value read from the xml nodes Employee e = new Employee(name,id,age,type); return e; } /** * I take a xml element and the tag name, look for the tag and get * the text content * i.e for <employee><name>John</name></employee> xml snippet if * the Element points to employee node and tagName is 'name' I will return John */ private String getTextValue(Element ele, String tagName) { String textVal = null; NodeList nl = ele.getElementsByTagName(tagName); if(nl != null && nl.getLength() > 0) { Element el = (Element)nl.item(0); textVal = el.getFirstChild().getNodeValue(); } return textVal; } /** * Calls getTextValue and returns a int value */ private int getIntValue(Element ele, String tagName) { //in production application you would catch the exception return Integer.parseInt(getTextValue(ele,tagName)); } d) Iterating and printing. private void printData(){ System.out.println("No of Employees '" + myEmpls.size() + "'."); Iterator it = myEmpls.iterator(); while(it.hasNext()) { System.out.println(it.next().toString()); } } Using Sax: SAXParserExample.java a) Create a Sax Parser and parse the xml private void parseDocument() { //get a factory SAXParserFactory spf = SAXParserFactory.newInstance(); try { //get a new instance of parser

SAXParser sp = spf.newSAXParser(); //parse the file and also register this class for call backs sp.parse("employees.xml", this); }catch(SAXException se) { se.printStackTrace(); }catch(ParserConfigurationException pce) { pce.printStackTrace(); }catch (IOException ie) { ie.printStackTrace(); } } b) In the event handlers create the Employee object and call the corresponding setter methods. //Event Handlers public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { //reset tempVal = ""; if(qName.equalsIgnoreCase("Employee")) { //create a new instance of employee tempEmp = new Employee(); tempEmp.setType(attributes.getValue("type")); } } public void characters(char[] ch, int start, int length) throws SAXException { tempVal = new String(ch,start,length); } public void endElement(String uri, String localName, String qName) throws SAXException { if(qName.equalsIgnoreCase("Employee")) { //add it to the list myEmpls.add(tempEmp); }else if (qName.equalsIgnoreCase("Name")) { tempEmp.setName(tempVal); }else if (qName.equalsIgnoreCase("Id")) { tempEmp.setId(Integer.parseInt(tempVal)); }else if (qName.equalsIgnoreCase("Age")) { tempEmp.setAge(Integer.parseInt(tempVal)); } } c) Iterating and printing. private void printData(){ System.out.println("No of Employees '" + myEmpls.size() + "'.");

Iterator it = myEmpls.iterator(); while(it.hasNext()) { System.out.println(it.next().toString()); } } OUTPUT: Employee Details - Name:Seagull, Type:permanent, Id:3674, Age:34. Employee Details - Name:Robin, Type:contract, Id:3675, Age:25. Employee Details - Name:Crow, Type:permanent, Id:3676, Age:28. Result : Thus the Parsing an XML document using DOM and SAX Parsers is been done and executed successfully.
. Server Side Application Using JSP.

STUDENT INFORMATION SYTEM USING JSP AND SERVLET AIM: To develop the student webpage information using java servlet and JDBC. ALGORITHM : Start the program Create main HTML page for student database maintenance Select option to do the following operation Insertion, search ,delete and modify or update the student recode Main.Html <html> <body bgcolor=yellow text=red> <div align=center> <label><h2>Student database maintenance</h2> </label> <TABLE> <TR><TD><a href="http://localhost:7001/student/register.html">REGISTER</a></TD></T R> <TR><TD><a href="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></html> Register.HTML <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> registration </TITLE> </HEAD> <BODY bgcolor=teak text=red> <form action="http://localhost:7001/student/register1" method=post> <pre> Enter Id : <input type=text name="id" size=4 ><br> Enter Name : <input type=text name="name" size=20 ><br> Enter Age : <input type=text name="age" size=4 ><br> Enter Branch: <input type=text name="branch" size=10 ><br> Enter Mark1 : <input type=text name="m1" size=4 ><br> Enter Mark2 : <input type=text name="m2" size=4 ><br>

Enter Mark3 : <input type=text name="m3" size=4 ><br> Enter Grade : <input type=text name="grade" size=20 ><br> Click : <input type="submit" name="submit" value=register> </pre></form></BODY></HTML> Insert.Html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> registration </TITLE> </HEAD> <BODY bgcolor=teak text=red> <form action="http://localhost:7001/student/insert" method=post> <pre> <div align=center> Enter Id : <input type=text name="id" size=4 ><br> Enter Name : <input type=text name="name" size=20 ><br> Enter Age : <input type=text name="age" size=4 ><br> Enter Branch: <input type=text name="branch" size=10 ><br> Enter Mark1 : <input type=text name="m1" size=4 ><br> Enter Mark2 : <input type=text name="m2" size=4 ><br> Enter Mark3 : <input type=text name="m3" size=4 ><br> Enter Grade : <input type=text name="grade" size=4 ><br> <input type="submit" name="submit" value=register> </div></pre></form></BODY></HTML> Delete.Html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> DELETE STUDENT RECORD </TITLE></HEAD> <BODY bgcolor=yellow text=cyan> <form action="http://localhost:7001/student/delete2" method=post> <pre> Enter the ID :<input type=text name="idno" size=4 ><br> Click :<input type="submit" name=submit value=delete> </pre> </form> </BODY> </HTML> Second.java import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; import java.lang.*; public class second extends HttpServlet {

public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException { loginform(res,false); }//goGet() private void loginform(HttpServletResponse res,boolean error)throws ServletException,IOException { res.setContentType("text/html"); PrintWriter pr=res.getWriter(); pr.println("<html><body bgcolor=blue text=red>"); pr.println("<div align=center>"); if(error) { pr.println("<H2>LOGIN FAILED, PLEASE TRY AGAIN!!!</H2>"); } pr.println("<form method=post NAME=FORM>"); pr.println("<table><TR><TD><label> please enter your name and password</label></TR></TD>"); pr.println("<TR><TD>Username:<input type=text name=username> "); pr.println("<TR><TD>Password:<input type=password name=password><br></TR></TD><hr width=100%></TR></TD>"); pr.println("<TR><TD>Press:<input type=submit name=submit value=Continue></TR></TD>"); pr.println("<TR><TD>clear:<input type=reset name =reset value=Clear></TR></TD></TABLE>"); pr.println("</form></div></body></html>"); }//loginform() public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException { String name=req.getParameter("username"); String pass=req.getParameter("password"); if(logindb(name,pass)) { RequestDispatcher rd=req.getRequestDispatcher("/main.html"); rd.forward(req,res); } else { loginform(res,true); } }//doPost() boolean logindb(String name, String pass)

{ try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:logindb"); Statement s=con.createStatement(); String sql="select * from stu where username= '" + name + "' AND password= '" + pass + "' "; ResultSet rs=s.executeQuery(sql); if(rs.next()) { return true; } con.close(); } catch(SQLException s) { s.printStackTrace(); } catch(Exception e) { e.printStackTrace(); } return false; }//login() }; Register1.java /* INSERTING THE DATA */ import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; import java.sql.*; import java.lang.*; public class register1 extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException { try { res.setContentType("Text/html"); PrintWriter pr=res.getWriter(); int id=Integer.parseInt(req.getParameter("id")); String name=req.getParameter("name");

int age=Integer.parseInt(req.getParameter("age")); String branch=req.getParameter("branch"); int m1=Integer.parseInt(req.getParameter("m1")); int m2=Integer.parseInt(req.getParameter("m2")); int m3=Integer.parseInt(req.getParameter("m3")); String grade=req.getParameter("grade"); pr.println("<html><body bgcolor=yellow text=red><div align=center>"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:ss"); //pr.println("student information are successfully registered"); //pr.println("<a href=http://localhost:7001/student/main.html>goto main page</a>"); PreparedStatement pst=con.prepareStatement("Insert into studata values(?,?,?,?,?,?,?,?) "); 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("student information are successfully registered"); pr.println("<a href=http://localhost:7001/student/main.html>goto main page</a>"); pr.println("</html></body>"); con.commit(); } catch(SQLException e) { System.out.println(e.getMessage()); } catch(Exception e) { e.printStackTrace(); } } }; Insert.java import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; import java.sql.*;

import java.lang.*; public class register extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException { try { res.setContentType("Text/html"); PrintWriter pr=res.getWriter(); int id=Integer.parseInt(req.getParameter("id")); String name=req.getParameter("name"); int age=Integer.parseInt(req.getParameter("age")); String branch=req.getParameter("branch"); int m1=Integer.parseInt(req.getParameter("m1")); int m2=Integer.parseInt(req.getParameter("m2")); int m3=Integer.parseInt(req.getParameter("m3")); String grade=req.getParameter("grade"); pr.println("<html><body bgcolor=yellow text=red><div align=center>"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:ss"); // pr.println("Get connection"); PreparedStatement pst=con.prepareStatement("Insert into studata values(?,?,?,?,?,?,?,?) "); 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(); con.commit(); pr.println("student information are successfully registered"); pr.println("<a href=http://localhost:7001/student/main.html>goto main page</a>"); pr.println("</html></body>"); con.close(); } catch(SQLException e) { System.out.println(e.getMessage()); } catch(Exception e)

{ e.printStackTrace(); } } }; Find3.Java /* SEARCH THE PARTICULAR RECORD */ import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; import java.sql.*; import java.lang.*; public class find3 extends HttpServlet { public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException { res.setContentType("Text/html"); PrintWriter pr=res.getWriter(); pr.println("<html><body bgcolor=black text=green><div align=center>"); pr.println("<form action=http://localhost:7001/student/find3 method=post name=form1>"); pr.println("<h4>Enter the student ID:</h4><input type=text name=id >"); pr.println("<h4>click:</h4><input type=submit name=submit value=search>"); pr.println("</form></div></body></html>"); } public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException { try { res.setContentType("Text/html"); PrintWriter pr=res.getWriter(); String id =req.getParameter("id"); int idno=Integer.parseInt(id); pr.println("<html><body bgcolor=black text=green><div align=center>"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:ss"); //PreparedStatement pst=con.prepareStatement("select * from studata where ID= '" + idno + "' "); PreparedStatement pst=con.prepareStatement("select * from studata where

ID= ? "); pst.setInt(1,idno); ResultSet r=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("<a href=http://localhost:7001/student/main.html>goto main page</a>"); pr.println("</html></body>"); } catch(SQLException e) { System.out.println(e.getMessage()); } catch(Exception e) { e.printStackTrace(); } } }; Delete2.java import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; import java.sql.*; import java.lang.*; public class delete2 extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException { try { res.setContentType("Text/html"); PrintWriter pr=res.getWriter(); pr.println("<html><body bgcolor=black text=yellow>"); String idno=req.getParameter("idno"); int id=Integer.parseInt(idno); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:ss"); pr.println("get connected");

//PreparedStatement pst=con.prepareStatement("Delete from studata where ID= '" + id + "' "); PreparedStatement pst=con.prepareStatement("Delete from studata where ID= ? "); pst.setInt(1,id); pst.executeUpdate(); pr.println("<h2>student record is successfully deleted"); pr.println("<a href=http://localhost:7001/student/main.html>goto main page</a>"); pr.println("</html></body>"); con.commit(); } catch(SQLException e) { System.out.println(e.getMessage()); } catch(Exception e) { e.printStackTrace(); } } }; Output: Studenttable.

RESULT : Thus student information java script program is successfully completed.

7. WEB CUSTOMISATION

CREATION OF WEB APPLICATION USING PHP AIM: To create a calculator web appliction using php. ALGORITHM : Step1 : Start the program Step2 : Create a php web page calc.php Step3: Using form and input type tag create various buttons, textbox, radio button etc. Step4: calcute the output for various option Step5: using post method display the result in next page. Step6: Stop the program. Coding: Calc.php: <?php ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Calculator</title> </head> <body> <?php // basic calculator program function showForm() { ?> All field are required, however, if you forget any, we will put a random number in for you. <br /> <table border="0"> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <tr> <td>Number:</td> <td><input type="text" maxlength="3" name="number" size="4" /></td> </tr> <span id="square"> <tr> <td>Another number:</td> <td><input type="text" maxlength="4" name="number2" size="4" /></td> </tr> </span> <tr> <td valign="top">Operator:</td>

<td><input type="radio" name="opt" value="+" </>+<br /> <input type="radio" name="opt" value="-" />-<br /> <input type="radio" name="opt" value="*" />*<br /> <input type="radio" name="opt" value="/" />/<br /> <input type="radio" name="opt" value="^2" />x<sup>2</sup><br /> <input type="radio" name="opt" value="sqrt" />sqrt<br /> <input type="radio" name="opt" value="^" />^<br /> </td> </tr> <tr> <td>Rounding:</td> <td><input type="text" name="rounding" value="4" size="4" maxlength="4" /></td> <td><small>(Enter how many digits you would like to round to)</small> </td> </tr> <tr> <td><input type="submit" value="Calculate" name="submit" /></td> </tr> </form> </table> <?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[] = "You must select an operation.";

$error = true; } if (strpbrk($_POST['number'],"-") and strpbrk($_POST['number2'],"0.") and $_POST['opt'] == "^") { $errors[] = "You cannot raise a negative number to a decimal, this is impossible. <a href=\"http://hudzilla.org/phpwiki/index.php?title=Other_mathematical_conv ersion_functions\">Why?</a>"; $error = true; } if ($error != false) { echo "We found these errors:"; echo "<ul>"; foreach ($errors as $e) { echo "<li>$e</li>"; } echo "</ul>"; } else { switch ($_POST['opt']) { case "+": $result = (int)strip_tags($_POST['number']) + (int)strip_tags($_POST['number2']); echo "The answer to " . (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 answer to " . (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 answer to " . (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 "$result rounded up is $a"; echo "<br />";

$b = floor($result); echo "$result rounded down is $b"; echo "<br />"; $h = round($result,(int)$_POST['rounding']); echo "$result rounded to $_POST[rounding] digits is " . $h; break; case "^2": $result = (int)strip_tags($_POST['number']) * (int)strip_tags($_POST['number2']); $a = (int)$_POST['number2'] * (int)$_POST['number2']; echo "The answer to " . (int)$_POST['number'] . "<sup>2</sup> is " . $result; echo "<br />"; echo "The answer to " . (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 "The square root of " . (int)strip_tags($_POST['number']) . " is " . $result; echo "<br />"; echo "The square root of " . (int)strip_tags($_POST['number2']) . " is " . $sqrt2; echo "<br />"; echo "The square root of " . (int)strip_tags($_POST['number']) . " rounded to " . strip_tags($_POST[rounding]) . " digits is " . round($result,(int)$_POST['rounding']); echo "<br />"; echo "The square root of " . (int)strip_tags($_POST['number2']) . " rounded to " . strip_tags($_POST[rounding]) . " digits is " . 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 />"; ?> <a href="calc.php">Go Back</a> </body> </html>

CREATION OF WEB APPLICATION USING PHP AIM: To create a calculator web appliction using php. ALGORITHM : Step1 : Start the program Step2 : Create a php web page calc.php Step3: Using form and input type tag create various buttons, textbox, radio button etc. Step4: calcute the output for various option Step5: using post method display the result in next page. Step6: Stop the program. Coding: Calc.php: <?php ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Calculator</title> </head> <body> <?php // basic calculator program function showForm() { ?> All field are required, however, if you forget any, we will put a random number in for you. <br /> <table border="0"> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <tr> <td>Number:</td> <td><input type="text" maxlength="3" name="number" size="4" /></td> </tr> <span id="square"> <tr> <td>Another number:</td> <td><input type="text" maxlength="4" name="number2" size="4" /></td> </tr> </span> <tr> <td valign="top">Operator:</td> <td><input type="radio" name="opt" value="+" </>+<br />

<input type="radio" name="opt" value="-" />-<br /> <input type="radio" name="opt" value="*" />*<br /> <input type="radio" name="opt" value="/" />/<br /> <input type="radio" name="opt" value="^2" />x<sup>2</sup><br /> <input type="radio" name="opt" value="sqrt" />sqrt<br /> <input type="radio" name="opt" value="^" />^<br /> </td> </tr> <tr> <td>Rounding:</td> <td><input type="text" name="rounding" value="4" size="4" maxlength="4" /></td> <td><small>(Enter how many digits you would like to round to)</small> </td> </tr> <tr> <td><input type="submit" value="Calculate" name="submit" /></td> </tr> </form> </table> <?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[] = "You must select an operation."; $error = true;

} if (strpbrk($_POST['number'],"-") and strpbrk($_POST['number2'],"0.") and $_POST['opt'] == "^") { $errors[] = "You cannot raise a negative number to a decimal, this is impossible. <a href=\"http://hudzilla.org/phpwiki/index.php?title=Other_mathematical_conv ersion_functions\">Why?</a>"; $error = true; } if ($error != false) { echo "We found these errors:"; echo "<ul>"; foreach ($errors as $e) { echo "<li>$e</li>"; } echo "</ul>"; } else { switch ($_POST['opt']) { case "+": $result = (int)strip_tags($_POST['number']) + (int)strip_tags($_POST['number2']); echo "The answer to " . (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 answer to " . (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 answer to " . (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 "$result rounded up is $a"; echo "<br />"; $b = floor($result);

echo "$result rounded down is $b"; echo "<br />"; $h = round($result,(int)$_POST['rounding']); echo "$result rounded to $_POST[rounding] digits is " . $h; break; case "^2": $result = (int)strip_tags($_POST['number']) * (int)strip_tags($_POST['number2']); $a = (int)$_POST['number2'] * (int)$_POST['number2']; echo "The answer to " . (int)$_POST['number'] . "<sup>2</sup> is " . $result; echo "<br />"; echo "The answer to " . (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 "The square root of " . (int)strip_tags($_POST['number']) . " is " . $result; echo "<br />"; echo "The square root of " . (int)strip_tags($_POST['number2']) . " is " . $sqrt2; echo "<br />"; echo "The square root of " . (int)strip_tags($_POST['number']) . " rounded to " . strip_tags($_POST[rounding]) . " digits is " . round($result,(int)$_POST['rounding']); echo "<br />"; echo "The square root of " . (int)strip_tags($_POST['number2']) . " rounded to " . strip_tags($_POST[rounding]) . " digits is " . 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 />"; ?> <a href="calc.php">Go Back</a> </body> </html>


Output:

Result: Thus the calculator web appliction using php is been developed succesfully.

EX NO. 8

DEVELOPMENT OF E-BUSINESS APPLICATION.

AIM: To create a calculator web appliction using php. ALGORITHM : Step1: Start the program Step2: Create a php web page contact.php Step3: Using form and input type tag create various buttons, textbox, radio button etc. Step4: Get the necessary field from the user. Step5: Using post method display the result in next page. Step6: Stop the program. Coding: Contact.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Web and Crafts</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body><!-- #header-wrapper --> <?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 ("Do NOT try that! ! "); } if(!$email == "" && (!strstr($email,"@") || !strstr($email,"."))) { echo "<h2>Use Back - Enter valid e-mail</h2>\n"; $badinput = "<h2>Feedback was NOT submitted</h2>\n"; echo $badinput; $error=1;

} if(empty($name) || empty($phonenumber) || empty($email ) || empty($message)) { echo "<h2>Use Back - fill in all required fields </h2>\n"; $error=1; } if($error!=1){ $todayis = date("l, F j, Y, g:i a") ; $attn = $subject ; $subject = "mail from $email"; $message = stripcslashes($message); $mailmessage = " $todayis [EST] \n Subject: $subject \n Message: $message \n From: $name ($email)\n City: $city\n Pin/Zip code: $zip\n PhoneNo: $phonenumber\n "; $from ="From: $email \r\n"; mail("[email protected]" ,$subject, $mailmessage,$from); echo "Thank You :"; echo "$name("; echo "$email )"; echo "for your interest in our services. We will contact you soon <br>"; } else { echo "Use Back and Fill all required fields !!"; } } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" id="form1"> <table cellspacing="0" cellpadding="2" width="100%" border="0" class="text_main"> <tr> <td align="right" valign="center"><strong><font color="#ff0000">*</font>&nbsp;Name : </strong></td> <td align="left" valign="center"><input style="WIDTH: 207px; HEIGHT: 22px" size="26" name="name" /></td> </tr> <tr> <td align="right" valign="center"><strong>Address :</strong></td> <td align="left" valign="center"><textarea style="WIDTH: 205px; HEIGHT: 80px" name="address" rows="6" cols="22"></textarea></td>

</tr> <tr> <td align="right" valign="center"><strong>City :</strong></td> <td align="left" valign="center"><input style="WIDTH: 205px; HEIGHT: 22px" size="26" name="city" /></td> </tr> <tr> <td align="right" valign="center"><strong><font color="#ff0000">*</font>&nbsp;Phone No :</strong></td> <td align="left" valign="center"><input style="WIDTH: 168px; HEIGHT: 22px" size="21" name="phonenumber" /></td> </tr> <tr> <td align="right" valign="center"><strong><font color="#ff0000">*</font>&nbsp;Email :</strong></td> <td align="left" valign="center"><input style="WIDTH: 207px; HEIGHT: 22px" size="26" name="email" /></td> </tr> <tr> <td align="right" valign="center"><strong><font color="#ff0000">*</font>&nbsp;Your Message :</strong></td> <td align="left" valign="center"><textarea style="WIDTH: 346px; HEIGHT: 158px" name="message" rows="8" cols="37"></textarea></td> </tr> <tr> <td valign="center" align="right"></td> <td valign="center" align="left"><input type="submit" value="Send" name="submit" /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="reset" value="Clear" name="reset" /></td> </tr> <tr> <td valign="center" align="right"></td> <td valign="center" align="left" height="15" ></td> </tr> <tr> <td align="right" valign="center"></td> <td align="left" valign="center">Fields marked <font color="#ff0000">*</font> are mandatory</td> </tr> </table> </form>

<?php } ?> </body> </html> Sample output:

RESULT: Thus the Php application has been developed and executed successfully.
Aim :

AboutUs.php
<?php session_start(); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>EBookBiz Demo</title> <link href="css/stylesheet.css" type="text/css" rel="stylesheet" /> </head>

<body> <div id="wrapper"> <!-- header starts--> <?php include_once 'Header.php'; ?><!-- header ends -->

<div id="content"> <p><br /> <br /> <br />

<span class="font14b">

We are an online store selling IT and Computer related books. We serve student community and offer special discounts to students. <br /> <br /> Contact Us for more details</span></p> <p><span class="font14b">EBookBiz<br /> Tirupur<br /> Phone : 0421 4255202<br /> email : [email protected]<br /> <br /> <br /> Register today to Shop for Books!<br /> <br /> <br /> </span></p> </div> <div id="footer"> </div> </div>

</body> </html>

Order.php
<?php session_start(); include ('Db.php'); if(!isset($_SESSION['ses_username']))

{ header("Location:Login.php"); } $aOrderDetails = $_SESSION['orderdetails']; ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>EBookBiz Demo</title> <link href="css/stylesheet.css" type="text/css" rel="stylesheet" /> </head>

<body> <div id="wrapper"> <!-- header starts--> <?php include_once 'Header.php'; ?><!-- header ends -->

<div id="content"> Selected Books <br /> <br /> <table width="500" border="1" cellpadding="5" cellspacing="0"> <tr> <td width="43" align="center" valign="top" bgcolor="#FFFFCC">S.No</td>

<td width="342" align="left" valign="top" bgcolor="#FFFFCC">Book Title</td> <td width="77" align="left" valign="top" bgcolor="#FFFFCC">Price (Rs)</td> </tr> <?php $selectedBooks = $aOrderDetails['fSelectBook']; $sno = 1; $total = 0; $numBooks = count($selectedBooks); for($i=0; $i<$numBooks; $i++) { $query = "SELECT id, title, price FROM books WHERE id = ".$selectedBooks[$i]; $result = mysql_query($query);

if($row = mysql_fetch_assoc($result)) { $title = $row['title']; $price = $row['price']; $total += $price; ?> <tr> <td align="left" valign="top"><?php echo $sno; ?></td> <td align="left" valign="top"><?php echo $title; ?></td> <td align="right" valign="top"><?php echo $price; ?></td> </tr> <?php }

$sno++; } ?> <tr> <td colspan="2" align="right" valign="top">Total Amount (Rs) </td> <td align="right" valign="top"><?php echo number_format($total,2,'.',','); ?></td> </tr> </table>

</div>

<div id="footer">

</div>

</div>

</body> </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']); } ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>EBookBiz Demo</title> <link href="css/stylesheet.css" type="text/css" rel="stylesheet" /> </head>

<body> <div id="wrapper"> <!-- header starts-->

<?php include_once 'Header.php'; ?><!-- header ends -->

<div id="content"> <br /> <br /> <br /> <br /> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="deptform"> <table width="332" border="0" align="center" cellpadding="5" cellspacing="1" class="tabBorder"> <tr> <td colspan="2" align="left" valign="top" bgcolor="#CCCCCC">&nbsp;</td> </tr> <tr> <td width="144" align="right" valign="top" bgcolor="#EAEAEA">Choose the Department </td> <td width="168" align="left" valign="top" bgcolor="#EAEAEA"><label> <select name="fDepartment"> <option>Select Department</option> <option value="1">Computer Science</option> <option value="2">IT</option> </select> </label></td> </tr> <tr> <td colspan="2" align="center" valign="top" bgcolor="#EAEAEA"><label>

<input type="submit" name="seldept" value="Show Book List" /> </label></td> </tr> </table> </form> <br /> <br /> <br /> <br /> <br /> <span class="font14b"> <div id="footer"> </div> </div> </body> </html> </span> </div>

BOOKLIST.PHP
<?php 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"); } ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>EBookBiz Demo</title> <link href="css/stylesheet.css" type="text/css" rel="stylesheet" /> </head>

<body> <div id="wrapper">

<!-- header starts--> <?php include_once 'Header.php'; ?><!-- header ends --> <div id="content"> <br /> <br /> <br /><br /> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="deptform"> <input type="hidden" name="fDepartment" value="<?php echo $_REQUEST['fDepartment']; ?>" /> <table width="799" border="1" align="center" cellpadding="5" cellspacing="0"> <tr> <td width="39" align="center" valign="top" bgcolor="#FFFFCC">S.No</td> <td width="394" align="left" valign="top" bgcolor="#FFFFCC">Book Title</td> <td width="154" align="left" valign="top" bgcolor="#FFFFCC">Author Name</td> <td width="72" align="left" valign="top" bgcolor="#FFFFCC">Price</td> <td width="78" align="center" valign="top" bgcolor="#FFFFCC">Add to Cart</td> </tr> <?php $dept = $_GET['fDepartment']; $query = "SELECT id, title, authorname, price, department FROM books WHERE department = ".$dept; $result = mysql_query($query, $con); $i = 1; while($row = mysql_fetch_assoc($result)) { ?>

<tr> <td align="center" valign="top"><?php echo $i; ?></td> <td align="left" valign="top"><?php echo $row['title']; ?></td> <td align="left" valign="top"><?php echo $row['authorname']; ?></td> <td align="left" valign="top">Rs. <?php echo $row['price']; ?></td> <td align="center" valign="top"> <input type="checkbox" name="fSelectBook[]" value="<?php echo $row['id']; ? >" /> </td> </tr> <?php $i = $i + 1; } ?> </table><br /> <br /> <div style="text-align:center;"> <input type="submit" name="fPlaceOrder" value="Place Order" /> </div> </form> <br /> <br /> <br /> <br /> <br /> <span class="font14b"> <div id="footer"> </div> </span> </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

<div id="header"> <div id="logo"> <span class="logoStyle">E-BOOK-BIZ</span> </div> <div id="navigation"> <a href="index.php" class="navLink">Home</a>&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;<a href="Login.php" class="navLink">Login</a>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp; <a href="Department.php" class="navLink">Department</a>&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;<a href="Feedback.php" class="navLink">Feedback</a> </div> <div style="text-align:right; font-family:'Trebuchet MS'; font-size:12px; fontweight:bold;">

<?php if(isset($_SESSION['ses_username'])) { echo 'Welcome '.$_SESSION['ses_username']; echo '&nbsp;|&nbsp;<a href="Logout.php" class="navLink">Logout</a>'; } ?>

</div> </div>

Index.php
<?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>EBookBiz Demo</title> <link href="css/stylesheet.css" type="text/css" rel="stylesheet" /> </head> <body> <div id="wrapper"> <!-- header starts--> <?php include_once 'Header.php'; ?><!-- header ends -->

<div id="content"> <br /> <br /> <br /> <span class="font14b"> Information Technology and Computer Science Books.<br /> <br /> <br /> Low Price editions at discount to students of UG and PG courses.<br /> <br /> <br /> Register today to Shop for Books!<br /> <br /> <br /> </span> </div> <div id="footer"> </div> </div> </body> </html>

<?php session_start(); include ('Db.php'); if(isset($_POST['Submit'])) { $login_id = $_POST['fLoginId']; $password = $_POST['fPassword']; $query = "SELECT username FROM users WHERE login_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 = "Please provide correct login id and password"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>EBookBiz Demo</title> <link href="css/stylesheet.css" type="text/css" rel="stylesheet" /> </head>

<body> <div id="wrapper"> <!-- header starts--> <?php include_once 'Header.php'; ?><!-- header ends --> <div id="content"> <br /> <br /> <br /> <br /> <div> <?php if(isset($resultmsg)) { echo $resultmsg; } ?> </div> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="loginform">

<table width="332" border="0" align="center" cellpadding="5" cellspacing="1" class="tabBorder"> <tr> <td colspan="2" align="left" valign="top" bgcolor="#CCCCCC">Login</td> </tr> <tr> <td width="144" align="right" valign="top" bgcolor="#EAEAEA">Login ID </td> <td width="168" align="left" valign="top" bgcolor="#EAEAEA"><label> <input type="text" name="fLoginId" /> </label></td> </tr> <tr> <td align="right" valign="top" bgcolor="#EAEAEA">Password</td> <td align="left" valign="top" bgcolor="#EAEAEA"><input type="password" name="fPassword" /></td> </tr> <tr> <td colspan="2" align="center" valign="top" bgcolor="#ECECEC"><label> <input name="Submit" type="submit" value="Login" /> </label></td> </tr> <tr> <td colspan="2" align="left" valign="top" bgcolor="#ECECEC"><a href="Registration.php" class="navLink">New User ? Register</a></td> </tr> </table> </form>

<br /> <br /> <br /> <br /> <br /> <span class="font14b"> <div id="footer"> </div> </div> </body> </html> </span> </div>

Logout.php
<?php session_start(); session_destroy(); header("Location:index.php"); ?>

Registration.php

<?php session_start(); include ('Db.php'); if(!empty($_REQUEST['Submit'])) { //echo 'form submitted for registration...';

$name

= $_POST['fName'];

$address1 = $_POST['fAddress1']; $address2 = $_POST['fAddress2']; $city $state = $_POST['fCity']; = $_POST['fState'];

$pincode = $_POST['fPincode']; $phone $email = $_POST['fPhone']; = $_POST['fEmail'];

$login_id = $_POST['fLoginId']; $password = $_POST['fPassword'];

$query = "INSERT INTO users ( 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 = 'Registration successful.'; header("Location: Login.php?msg=success"); }?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">

<head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>EBookBiz Demo</title> <link href="css/stylesheet.css" type="text/css" rel="stylesheet" /> <script> function validate() { alert("ssssssssssssss");

var frm = document.forms['regform']; if(document.regform.fName.value == '') { alert("Please enter your Name)"; return false; } if(frm.fEmail.value == '') { alert("Please enter your Email"); return false; } if(frm.fLoginId.value == '') { alert("Please enter your Login Id"); return false; } if(frm.fPassword.value == '') {

alert("Please enter your Password"); return false; } } </script> </head>

<body> <div id="wrapper"> <!-- header starts--> <?php include_once 'Header.php'; ?><!-- header ends --> <div id="content"> <br /><br /> <br /><br /> <div> <?php if(isset($msg)) { //echo $msg; } ?> </div> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="regform" onsubmit="return validate();"> <table width="332" border="0" align="center" cellpadding="5" cellspacing="1" class="tabBorder"> <tr>

<td colspan="2" align="left" valign="top" bgcolor="#CCCCCC">Registration</td> </tr> <tr> <td width="144" align="right" valign="top" bgcolor="#EAEAEA">Name <em>*</em></td> <td width="168" align="left" valign="top" bgcolor="#EAEAEA"> <input name="fName" type="text" id="fName" /> </tr> <tr> <td width="144" align="right" valign="top" bgcolor="#EAEAEA">Address1</td> <td width="168" align="left" valign="top" bgcolor="#EAEAEA"> <input name="fAddress1" type="text" id="fAddress1" /> </tr> <tr> <td width="144" align="right" valign="top" bgcolor="#EAEAEA">Address2</td> <td width="168" align="left" valign="top" bgcolor="#EAEAEA"> <input name="fAddress2" type="text" id="fAddress2" /> </tr> <tr> <td width="144" align="right" valign="top" bgcolor="#EAEAEA">City</td> <td width="168" align="left" valign="top" bgcolor="#EAEAEA"> <input name="fCity" type="text" id="fCity" /> </tr> <tr> <td width="144" align="right" valign="top" bgcolor="#EAEAEA">State</td> <td width="168" align="left" valign="top" bgcolor="#EAEAEA"> <input name="fState" type="text" id="fState" /> </td> </td> </td> </td> </td>

</tr> <tr> <td width="144" align="right" valign="top" bgcolor="#EAEAEA">Pincode</td> <td width="168" align="left" valign="top" bgcolor="#EAEAEA"> <input name="fPincode" type="text" id="fPincode" /> </tr> <tr> <td width="144" align="right" valign="top" bgcolor="#EAEAEA">Phone Number </td> <td width="168" align="left" valign="top" bgcolor="#EAEAEA"> <input name="fPhone" type="text" id="fPhone" /> </tr> <tr> <td width="144" align="right" valign="top" bgcolor="#EAEAEA">Email ID <em>*</em></td> <td width="168" align="left" valign="top" bgcolor="#EAEAEA"> <input name="fEmail" type="text" id="fEmail" /> </tr> <tr> <td height="15" colspan="2" align="right" valign="top" bgcolor="#EAEAEA"></td> </tr> <tr> <td width="144" align="right" valign="top" bgcolor="#EAEAEA">Login ID <em>*</em></td> <td width="168" align="left" valign="top" bgcolor="#EAEAEA"> <input name="fLoginId" type="text" id="fLoginId" /> </tr> </td> </td> </td> </td>

<tr> <td width="144" align="right" valign="top" bgcolor="#EAEAEA">Password <em>*</em></td> <td width="168" align="left" valign="top" bgcolor="#EAEAEA"> <input name="fPassword" type="password" id="fPassword" /> </tr> <tr> <td colspan="2" align="center" valign="top" bgcolor="#EAEAEA"><label> <input type="submit" name="Submit" value="Submit" /> </label></td> </tr> </table> </form> <br /> <br /> <br /> <br /> <br /> <span class="font14b"> <div id="footer"> </div> </div> </body> </html> </span> </div> </td>

STYLESHEET

#wrapper { margin:auto; width: 980px; min-height: 600px; font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#333333; border-left:#333333 1px solid; border-right:#333333 1px solid; border-top:#333333 1px solid; border-bottom:#333333 1px solid; padding: 5px 5px 5px 5px;

} #header { width: 980px; height: 70px; border-bottom:#660000 1px dotted;

} #content {

width: 980px; padding:10px 10px 10px 10px;

} .logoStyle { font-family:"Trebuchet MS"; font-size:24px; font-weight:bold; color:#660000; } #navigation { padding-top:10px; }

.navLink { font-family: Verdana, Arial, Helvetica, sans-serif; font-size:12px; font-weight: bold; color:#333300; text-decoration:none; } .navLink:hover { font-family: Verdana, Arial, Helvetica, sans-serif; font-size:12px; font-weight: bold; color: #009900;

text-decoration:underline; } .font14b { font-family:Verdana, Arial, Helvetica, sans-serif; font-size:14px; font-weight:bold; color: #000000; } .tabBorder { border-bottom:#000000 1px solid; border-left:#000000 1px solid; border-top:#000000 1px solid; border-right:#000000 1px solid; } AboutUs.php

Login.php

RegistrationFrom.php

Department.php

Booklist.php

Order.php

You might also like