You are on page 1of 20

Main page:(main.

php)
<!doctype html>
<html>
<head>
<frameset rows="20%,*">
<frame src="topframe.php"name="f1">
<frame src="rightframe.php"name="f3">
</frameset>
</head>
</html>

Top frame:(topframe.php)
<html>
<body background="green.png">
<p>
<img src="books.jpg" align=left width=100 height=100">
<h1 align=center><u><i>Explorer Book Store</i></u></h1>
</p>
<br>
<p>
<h2>&nbsp;&nbsp;&nbsp;&nbsp;
<a href= "main.php" target="_parent">
Home
</a>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
<a href="login.php" target="f3">
login
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="register.php" target="f3">
registration
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="catalogue.php" target="f3">
Catalogue
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="index2.php" target="f3">
Cart
</a>
&nbsp;
</h2>
</p>
</body>
</html>

Right frame:(rightframe.php)
<html>
<body background="ee.jpg">
<p>
<h1 align="center"> <font face="times new roman" color="violet"
size=18><u>About Us </u></font> </h1>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;


<font face="Bodoni MT" color=white size=7 > This is the online book store for the
books explorers.
It contains book catalogue of various branches like General Knowledge, Competitive
Exams, B.Tech, 1-12th Standard students study material.<br/>
You can login and buy your favorite or desired books over here. <br/>
stay updated with the site for more information.</font>
</p>
</body>
</html>

Output:
Login:(login.php)
<?php include('server.php');?>
<!Doctype html>
<html>
<head>
<title> login page! </title>
<link rel="stylesheet" type="text/css" href="style1.css">
</head>
<body>
<center>
<div>
<h2><font face="comic sans ms">Login</font></h2>
<form action="process1.php" method="POST">
<label>
<font face="comic sans ms" color="black" size="5">User ID </font>
</label>
<input type="text" name="username" id="username"/>
<label><br><br>
<font face="comic sans ms" color="black" size="5">Password </font>
</label>
<input type="password" name="password" id="password"/> <br><br>
<input type="submit" value="Login" id="login"/>
</form>
</div>
</center>
</body>
</html>
Output:

Database-Connection:

Database Connection:
Registration:(register.php)
<?php include('server.php') ?>
<!DOCTYPE html>
<html>
<head>
<title>Registration</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body background ="ee.jpg">
<div class="header">
<h2>Register</h2>
</div>

<form method="post" action="register.php">

<?php include('errors.php'); ?>

<div class="input-group">
<label>Username</label>
<input type="text" name="username" value="<?php echo
$username; ?>">
</div>
<div class="input-group">
<label>Email</label>
<input type="email" name="email" value="<?php echo $email; ?>">
</div>
<div class="input-group">
<label>Password</label>
<input type="password" name="password_1">
</div>
<div class="input-group">
<label>Confirm password</label>
<input type="password" name="password_2">
</div>
<div class="input-group">
<button type="submit" class="btn"
name="reg_user">Register</button>
</div>
<p>
Already a member? <a href="login.php">Sign in</a>
</p>
</form>
</body>
</html>

Style.css:
*{
margin: 0px;
padding: 0px;
}
body {
font-size: 120%;
background: linear-gradient(black,white,orange,);
}

.header {
width: 30%;
margin: 50px auto 0px;
color: white;
background: #5F9EA0;
text-align: center;
border: 1px solid #B0C4DE;
border-bottom: none;
border-radius: 10px 10px 0px 0px;
padding: 20px;
}
form, .content {
width: 30%;
margin: 0px auto;
padding: 20px;
border: 1px solid #B0C4DE;
background: linear-gradient(skyblue,white,orange);
border-radius: 0px 0px 10px 10px;
}
.input-group {
margin: 10px 0px 10px 0px;
}

.input-group label {
display: block;
text-align: left;
margin: 3px;
}
.input-group input {
height: 30px;
width: 93%;
padding: 5px 10px;
font-size: 16px;
border-radius: 5px;
border: 1px solid gray;
}
.btn {
padding: 10px;
font-size: 15px;
color: white;
background: #5F9EA0;
border: none;
border-radius: 5px;
}
.error {
width: 92%;
margin: 0px auto;
padding: 10px;
border: 1px solid #a94442;
color: #a94442;
background: #f2dede;
border-radius: 5px;
text-align: left;
}
.success {
color: #3c763d;
background: #dff0d8;
border: 1px solid #3c763d;
margin-bottom: 20px;
}
Output:

Database Connection:

Catalogue:(catalogue.php)
<html>
<head>
<title> Catalogue </title>
</head>
<body background="qq.jpg">
<center>
<table border=1>
<tr>
<th> Book Preview </th>
<th> Book Details </th>
<th> Price </th>
<th> Payment </th>
</tr>
<tr>
<td> <img src="xml.jpg" width=150 height=150>
</img>
</td>
<td>
<pre>
<font face="comic sans ms" size=4 color="white" >
book:XML Bible
Author:winston
Publisher:Wiesley
</font>
</pre>
</td>
<td>&nbsp;400/- &nbsp; </td>
<td> &nbsp; &nbsp; <a href="index2.php" target="_blank">
<img src="cart.bmp" width="150" height="100"></img>
</a> &nbsp; &nbsp;
</td>
</tr>
<tr>
<td> <img src="java.bmp" width="150" height="150">
</img>
</td>
<td>
<pre>
<font face="comic sans ms" size=4 color="white" >
book:Java 2
Author:Watson
Publisher:BPB publications
</font>
</pre>
</td>
<td>&nbsp; 650/- &nbsp;</td>
<td> &nbsp; &nbsp; <a href="index2.php" target="_blank">
<img src="cart.bmp" width="150" height="100"></img>
</a> &nbsp; &nbsp;
</td>
</tr>
<tr>
<td> <img src="cc0.jpg" width=150 height=150>
</img>
</td>
<td>
<pre>
<font face="comic sans ms" size=4 color="white" >
book:Cloud Computing
Author:Kris Jamsa
Publisher:Jones and Barlet
</font>
</pre>
</td>
<td>&nbsp;390/- &nbsp; </td>
<td> &nbsp; &nbsp; <a href="index2.php" target="_blank">
<img src="cart.bmp" width="150" height="100"></img>
</a> &nbsp; &nbsp;
</td>
</tr>
<tr>
<td> <img src="os.jpg" width=150 height=150>
</img>
</td>
<td>
<pre>
<font face="comic sans ms" size=4 color="white" >
book:Operating System Concepts
Author:Greg Gangne
Publisher:Wiesley
</font>
</pre>
</td>
<td>&nbsp;240/- &nbsp; </td>
<td> &nbsp; &nbsp; <a href="index2.php" target="_blank">
<img src="cart.bmp" width="150" height="100"></img>
</a> &nbsp; &nbsp;
</td>
</tr>
<tr>
<td> <img src="cc1.jpg" width=150 height=150>
</img>
</td>
<td>
<pre>
<font face="comic sans ms" size=4 color="white" >
book:Compilers
Author:Ullman
Publisher:Pearson International
</font>
</pre>
</td>
<td>&nbsp;350/- &nbsp; </td>
<td> &nbsp; &nbsp; <a href="index2.php" target="_blank">
<img src="cart.bmp" width="150" height="100"></img>
</a> &nbsp; &nbsp;
</td>
</tr>
<tr>
<td> <img src="cc4.jpg" width=150 height=150>
</img>
</td>
<td>
<pre>
<font face="comic sans ms" size=4 color="white" >
book:Computer System Architecture
Author:M.Morris Mano
Publisher:Pearson
</font>
</pre>
</td>
<td>&nbsp;400/- &nbsp; </td>
<td> &nbsp; &nbsp; <a href="index2.php" target="_blank">
<img src="cart.bmp" width="150" height="100"></img>
</a> &nbsp; &nbsp;
</td>
</tr>
</table> </center>
</body>
</html>

Output:
Cart:(index2.php)

<?php
session_start();
$connect = mysqli_connect("localhost", "root", "", "cart");
if(isset($_POST["add_to_cart"]))
{
if(isset($_SESSION["shopping_cart"]))
{
$item_array_id = array_column($_SESSION["shopping_cart"], "item_id");
if(!in_array($_GET["id"], $item_array_id))
{
$count = count($_SESSION["shopping_cart"]);
$item_array = array(
'item_id' => $_GET["id"],
'item_name' => $_POST["hidden_name"],
'item_price' => $_POST["hidden_price"],
'item_quantity' => $_POST["quantity"]);
$_SESSION["shopping_cart"][$count] = $item_array;
}
else
{
echo '<script>alert("Item Already Added")</script>';
echo '<script>window.location="index2.php"</script>';
}
}
else
{
$item_array = array(
'item_id' => $_GET["id"],
'item_name' => $_POST["hidden_name"],
'item_price' => $_POST["hidden_price"],
'item_quantity' => $_POST["quantity"]);
$_SESSION["shopping_cart"][0] = $item_array;
}
}
if(isset($_GET["action"]))
{
if($_GET["action"] == "delete")
{
foreach($_SESSION["shopping_cart"] as $keys => $values)
{
if($values["item_id"] == $_GET["id"])
{
unset($_SESSION["shopping_cart"][$keys]);
echo '<script>alert("Item Removed")</script>';
echo '<script>window.location="index2.php"</script>';}}}}
?>
<!DOCTYPE html>
<html>
<head>
<title>Shopping Cart</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js">
</script>
<linkrel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js">
</script>
</head>
<body background="qq.jpg">
<br />
<div class="container" style="width:700px;">
<h3 align="center">Cart</h3><br />
<?php
$query = "SELECT * FROM tblproduct ORDER BY id ASC";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{while($row = mysqli_fetch_array($result))
?>
<div class="col-md-4">
<form method="post" action="index2.php?action=add&id=<?php echo
$row["id"]; ?>">
<div style="border:1px solid #333; background-color:#f1f1f1; border-radius:5px;
padding:16px;" align="center">
<img src="<?php echo $row["image"]; ?>" class="img-responsive" />
<br />
<h4 class="text-info"><?php echo $row["book name"]; ?></h4>
<h4 class="text-danger">$ <?php echo $row["price"]; ?></h4>
<input type="text" name="quantity" class="form-control" value="1" />
<input type="hidden" name="hidden_name" value="<?php echo $row["book
name"]; ?>" />
<input type="hidden" name="hidden_price" value="<?php echo $row["price"]; ?
>" />
<input type="submit" name="add_to_cart" style="margin-top:5px;" class="btn
btn-success" value="Add to Cart" />
</div>
</form>
</div>
<?php
}}
?>
<div style="clear:both">
</div>
<br />
<h3>Order Details</h3>
<div class="table-responsive">
<table class="table table-bordered">
<tr>
<th width="40%">Item Name</th>
<th width="10%">Quantity</th>
<th width="20%">Price</th>
<th width="15%">Total</th>
<th width="5%">Action</th>
</tr>
<?php
if(!empty($_SESSION["shopping_cart"]))
{ $total = 0;
foreach($_SESSION["shopping_cart"] as $keys => $values)
{ ?>
<tr>
<td><?php echo $values["item_name"]; ?></td>
<td><?php echo $values["item_quantity"]; ?></td>
<td>$ <?php echo $values["item_price"]; ?></td>
<td>$ <?php echo number_format($values["item_quantity"] *
$values["item_price"], 2); ?>
</td><td>
<a href="index2.php?action=delete&id=<?php echo $values["item_id"]; ?
>"><span class="text-danger">Remove</span></a></td>
</tr>
<?php
$total = $total + ($values["item_quantity"] * $values["item_price"]);
} ?>
<tr>
<td colspan="3" align="right">Total</td>
<td align="right">$ <?php echo number_format($total, 2); ?>
</td>
<td></td>
</tr>
<?php
} ?>
</table>
</div>
</div>
<br />
</body>
</html>
Output:

Database Connection:

Process1.php:

<?php

$connect = new mysqli('localhost', 'root', '','login');


if($connect -> connect_error){
die('connection failed');
}
else echo 'connected successfully';
$username = $_POST['username'];
$password = $_POST['password'];

$sql = "select name FROM login where username = '$username' AND password =
'$password'" ;
$result= $connect->query($sql);

if($result-> num_rows>0)
{
while($row= $result->fetch_assoc())
{
echo "<br> Admin name is:". $row["name"];
}
}
else echo "<br> username and password not matched";

?>

Server.php:

<?php
session_start();

// variable declaration
$username = "";
$email = "";
$errors = array();
$_SESSION['success'] = "";

// connect to database
$db = mysqli_connect('localhost', 'root', '', 'registration');

// REGISTER USER
if (isset($_POST['reg_user'])) {
// receive all input values from the form
$username = mysqli_real_escape_string($db, $_POST['username']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
$password_2 = mysqli_real_escape_string($db, $_POST['password_2']);

// form validation: ensure that the form is correctly filled


if (empty($username)) { array_push($errors, "Username is required"); }
if (empty($email)) { array_push($errors, "Email is required"); }
if (empty($password_1)) { array_push($errors, "Password is required"); }

if ($password_1 != $password_2) {
array_push($errors, "The two passwords do not match");
}

// register user if there are no errors in the form


if (count($errors) == 0) {
$password = md5($password_1);//encrypt the password before saving
in the database
$query = "INSERT INTO users (username, email, password)
VALUES('$username', '$email', '$password')";
mysqli_query($db, $query);

$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: index.php');
}

// ...

// LOGIN USER
if (isset($_POST['login_user'])) {
$username = mysqli_real_escape_string($db, $_POST['username']);
$password = mysqli_real_escape_string($db, $_POST['password']);

if (empty($username)) {
array_push($errors, "Username is required");
}
if (empty($password)) {
array_push($errors, "Password is required");
}

if (count($errors) == 0) {
$password = md5($password);
$query = "SELECT * FROM users WHERE username='$username' AND
password='$password'";
$results = mysqli_query($db, $query);

if (mysqli_num_rows($results) == 1) {
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: index.php');
}else {
array_push($errors, "Wrong username/password combination");
}
}
}

?>

Error.php:

<?php if (count($errors) > 0) : ?>


<div class="error">
<?php foreach ($errors as $error) : ?>
<p><?php echo $error ?></p>
<?php endforeach ?>
</div>
<?php endif ?>

You might also like