Sunteți pe pagina 1din 65

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>
DomParser Example.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));
}
}

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.

EX.NO.6
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:
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

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>
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:
Student table:

RESULT :
Thus student information java script program is successfully completed

EX NO:07.
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/xhtml1strict.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/xhtml1strict.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("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>&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>

OUTPUT:

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

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 : ebookbiz@gmail.com<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"> </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>
<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">
</span>
</div> <div id="footer">
</div>
</div>
</body>
</html>
Db.php
<?php
$db_hostname = 'localhost';
$db_dbname = 'ebookbiz';
$db_username = 'root';
$db_password = '';
$con = mysql_pconnect($db_hostname, $db_username, $db_password);
mysql_select_db($db_dbname, $con); ?>
Header.php
<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; font-weight: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">
</span>

</div>
<div id="footer">
</div>
</div>
</body>
</html>
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 = $_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'];
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" />
</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>
<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" />
</td>
</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>
</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" />
</td>
</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" />
</td>
</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" />
</td>
</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" />
</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>
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:

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