Professional Documents
Culture Documents
Date
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.
Source Code:
<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";
5108 GTEC
}
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>
5108 GTEC
<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
5108 GTEC
form.total.value=due;
}
</script>
</body>
</html>
Output:
Total Order Form:
5108 GTEC
Result:
Thus the designing web pages using client side scripting and DHTML has been
executed and verified successfully.
Ex No : 02
Date
Aim:
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.
Source Code:
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 %>
5108 GTEC
<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">
5108 GTEC
5108 GTEC
Result:
Thus the Client Server Scripting Programs has been executed and verified successfully
Ex No : 03
Date
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.
5108 GTEC
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.
Source Code:
10
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);
}
5108 GTEC
11
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");
5108 GTEC
12
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
5108 GTEC
13
tmp,filename));
if(system (fpBuffer)==(-1))
{
perror("email failure");
exit(EXIT_FAILURE);
5108 GTEC
14
}
}
}
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..
5108 GTEC
15
Result:
Thus the program for developing E-mail and file transfer protocols application has
been executed and verified successfully .
Ex No : 04
Date
Aim:
To develop a web service program for calculating Factorial of a number.
Algorithm:
1. Start the program.
2. Give one parameter name x
3. Data type as int
4. Click on ok
5. 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
Source Code:
package pack1;
5108 GTEC
16
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();
}
}
5108 GTEC
17
Output:
Web service program for factorial of a number:
5108 GTEC
18
Result:
Thus the Client Server Scripting Programs has been executed and verified successfully.
Ex No : 05
Date
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
5108 GTEC
19
Source Code:
Using Sax:
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>
DomParser Example.java
a) Getting a document builder
private void parseXmlFile(){
//get the factory
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
try {
5108 GTEC
20
21
22
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){
5108 GTEC
23
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));
}
}
c) Iterating and printing.
private void printData(){
System.out.println("No of Employees '" + myEmpls.size() + "'.");
Iterator it = myEmpls.iterator();
5108 GTEC
24
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 has been executed
and verified successfully.
Ex No : 06
Date
Aim:
To develop the student webpage information using java servlet and JDBC.
Algorithm :
Step 1: Start the program
Step 2:Create main HTML page for student database maintenance
Step 3: Select option to do the following operation Insertion, search, delete and modify or
update the student recode
Source Code:
Main.Html
5108 GTEC
25
<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>
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>
5108 GTEC
26
27
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>"); }
5108 GTEC
28
//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.jav
/* INSERTING THE DATA */
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
5108 GTEC
29
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>");
5108 GTEC
30
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");
5108 GTEC
31
// 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 {
5108 GTEC
32
33
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) {
5108 GTEC
34
System.out.println(e.getMessage()); }
catch(Exception e) {
e.printStackTrace();
}}
};
Output:
Student table:
5108 GTEC
35
5108 GTEC
36
5108 GTEC
37
Result:
Thus student information java script program has been executed and verified successfully .
5108 GTEC
38
Ex No : 07
Date
Web Customisation
Aim:
To create a calculator web application 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.
Source Code:
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() {
?>
5108 GTEC
39
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>
5108 GTEC
40
</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;
}
5108 GTEC
41
42
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;
5108 GTEC
43
5108 GTEC
44
5108 GTEC
45
5108 GTEC
46
Result:
Thus the calculator web application using PHP has been executed and verified
successfully.
Ex No : 08
Date
Aim:
To develop a E-Business application 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 displays the result in next page.
Step6: Stop the program.
5108 GTEC
47
Source Code:
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";
5108 GTEC
48
$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("99abin@gmail.com" ,$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> 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">
5108 GTEC
49
<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> 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> 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> 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>
5108 GTEC
50
</td>
</td>
5108 GTEC
51
AboutUs.php:
5108 GTEC
52
<?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 : ebookbiz@gmail.com<br />
<br />
<br />
Register today to Shop for Books!<br />
<br />
<br />
5108 GTEC
53
</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
5108 GTEC
54
<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>
5108 GTEC
55
56
57
</form>
<br />
<br />
<br />
<br />
<br />
<span class="font14b">
</span>
</div>
<div id="footer">
</div>
</div>
</body>
</html>
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>
5108 GTEC
58
<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>
5108 GTEC
59
60
61
<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>
5108 GTEC
62
<?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
5108 GTEC
63
64
65
session_start();
include ('Db.php');
if(!empty($_REQUEST['Submit']))
{
//echo 'form submitted for registration...';
$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 = "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'];
5108 GTEC
66
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 />
5108 GTEC
67
<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" />
</td>
</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" />
</td>
</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" />
</td>
</tr>
<tr>
5108 GTEC
68
69
</td>
<td width="168" align="left" valign="top" bgcolor="#EAEAEA">
<input name="fLoginId" type="text" id="fLoginId" />
</td>
</tr>
<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" />
</td>
</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">
</span>
</div>
<div id="footer">
</div>
</div>
</body>
</html>
5108 GTEC
70
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;
5108 GTEC
71
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;
}
Output:
AboutUs.php:
5108 GTEC
72
Login.php:
5108 GTEC
73
RegistrationFrom.php:
Department.php:
5108 GTEC
74
BookList.php:
Order.php:
5108 GTEC
75
Result:
Thus the E-Business Application using PHP has been executed and verified successfully.
5108 GTEC
76