Books PHP
Books PHP
A Project Report On
Online Book Shopping
1
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
TABLE OF CONTENT
2.1. Administrator 8
3.0.Web development 9
4.0.What is PHP. 9
5.0.What is MySql database. 10
6.0. Integrating the Website and Database 11
2
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
Introduction
An online bookstore software projects that acts as a central database containing
various books in stock along with their title, author and cost. This project is a
website that acts as a central book store. This web project is developed using php
as the front end and sql as a back-end. The sql database stores various book
related details. A user visiting the website can see a wide range of books
arranged in respective categories. The user may select desired book and view its
price. The user may even search for specific books on the website. Once the user
selects a book , he then has to fill in a form and the book is booked for the user.
The software has the following three main components:-
Purpose
For the project, we propose to build an online bookshop for People. The online
bookshop will contain stories, study material, any courses books like computer and
be available to everyone. Many students find textbooks too expensive to buy at
school bookstores and many courses only use the required textbooks a few days in
a semester. This becomes very wasteful and frustrating for students & others
people. This online bookstore provides a solution to this. It will provide a service
in which students can buy books online without any treble. There will be free
shipping. They do need to register with the site in order to books. Payment
information will be requested after adding any numbers of books in the cart.
.
3
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
Modules
The site will contain the following features:
Registration / Login
Add to Cart
Searching for book
Buy book
Payment option
Users:
Register-The user needs to be registered in order to login.
View product-Here the user can view different products and its details.
Search –The user can search product by name after which the system will evaluate
prices of the same product from different websites to give the user the best search
result.
Hardware Requirements:
Processor – i3
Hard Disk – 50 GB
Memory – 1GB RAM
Monitor
Software Requirement:
Windows 7 or higher
XAMMP control panel
Note pade ++
My SQL
4
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
Advantages:
Customers can get their book delivered instead of actually going and buying
the book. They can make payment online itself.
Managing of inventory in the shop for shopkeeper becomes easier as
customers are not visiting and ordering online.
This system saves both time and travelling cost of customers.
User can get to know different kinds of books that they were unaware of by
just searching in the system using keywords.
Applications:
The system can be very well used by the book shopkeepers to expand their
customers.
OVERALL DESCRIPTION
This project designs an online bookstore provides a web-based interface. It is the
graphical user interface. It have a form for user to input query information to
search the database. The users interface then pass the input to the control function,
which implemented in php. The control function is designed to process the input
from the users interface, generate the searching query and then gets data from the
database and returns to the users interface. The control functions also have bridges
to search some external real online bookshops. It can generate the query based on
the user input and pass them to the commercial bookshop. The bridge can also
handle the response from the commercial bookshop and parse the useful
information and display to the user in HTML forms.
For Administrators
5
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
<?php
echo "Hi, I'm a PHP script!";
?>
</body>
</html>
Advantages:
Stable: Since it is maintained by many developers, so when bugs are found, it can
be quickly fixed.
Easy to use: It uses C like syntax, so for those who are familiar with C, it’s very
easy for them to pick up and it is very easy to create website scripts.
6
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
7
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
DATABASE TABLES
ADMIBTb
BOOKSTb
CUSTOMERTb
8
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
ORDERTb
PUBLISHERid
dynamic Web page response to confirm the transaction. In either case, the Web
server is responsible for formatting the query results by adding HTML tags. The
Web server program then sends the program’s output back to the client’s browser
as a Web page.
The objective of this application is to provide the user an online website where
they can buy books from the comfort of their home. A shopping cart is used for the
purpose. The user can select the desired books, place them in the shopping cart and
purchase them using a Credit Card. The user’s order will be shipped according to
the type of shipping selected at the time of placing the order.
10
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
In order to design a web site, the relational database must be designed first.
Conceptual design can be divided into two parts: The data model and the process
model. The data model focuses on what data should be stored in the database while
the process model deals with how the data is processed. To put this in the context
of the relational database, the data model is used to design the relational tables.
The process model is used to design the queries that will access and perform
operations on those tables.
11
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
12
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
13
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
14
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
ER NOTATION
Entity Relationship Diagram (ERD) Symbols and Notations. There are three basic
elements in an ER Diagram: entity, attribute, relationship. There are more elements
which are based on the main elements. They are weak entity, multi valued attribute,
derived attribute, weak relationship, and recursive relationship.
Entities are objects or concepts that represent important data. Entities are typically
nouns such as product, customer, location, or promotion. There are three types of
entities commonly used in entity relationship diagrams.
15
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
16
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
ERD attributes are characteristics of the entity that help users to better understand the
database. Attributes are included to include details of the various entities that are
highlighted in a conceptual ER diagram.
17
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
18
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
ER DIAGRAM
address name
name address
phone
url
author publisher
url
Written by Published by
email
year address
phone
Shoping basket
stocks warehouse
address code
number
phone
19
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
Home page
PUBLISHERS
20
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
CONTACT US
21
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
CART
22
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
ADMIN LOGIN
ADD BOOKS
23
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
24
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
PAYMENT
CARD DETAILS
25
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
CODING
Admin.php
<?php
$title = "Administration section";
require_once "./template/header.php";
?>
<?php
require_once "./template/footer.php";
?>
26
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
Admin add.php
<?php
session_start();
require_once "./functions/admin.php";
$title = "Add new book";
require "./template/header.php";
require "./functions/database_functions.php";
$conn = db_connect();
if(isset($_POST['add'])){
$isbn = trim($_POST['isbn']);
$isbn = mysqli_real_escape_string($conn, $isbn);
$title = trim($_POST['title']);
$title = mysqli_real_escape_string($conn, $title);
$author = trim($_POST['author']);
$author = mysqli_real_escape_string($conn, $author);
$descr = trim($_POST['descr']);
$descr = mysqli_real_escape_string($conn, $descr);
$price = floatval(trim($_POST['price']));
$price = mysqli_real_escape_string($conn, $price);
$publisher = trim($_POST['publisher']);
$publisher = mysqli_real_escape_string($conn, $publisher);
// add image
if(isset($_FILES['image']) && $_FILES['image']['name'] != ""){
$image = $_FILES['image']['name'];
$directory_self =
str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
27
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
$uploadDirectory = $_SERVER['DOCUMENT_ROOT'] .
$directory_self . "bootstrap/img/";
$uploadDirectory .= $image;
move_uploaded_file($_FILES['image']['tmp_name'],
$uploadDirectory);
}
$query = "INSERT INTO books VALUES ('" . $isbn . "', '" . $title . "',
'" . $author . "', '" . $image . "', '" . $descr . "', '" . $price . "', '" . $publisherid . "')";
$result = mysqli_query($conn, $query);
if(!$result){
echo "Can't add new data " . mysqli_error($conn);
exit;
28
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
} else {
header("Location: admin_book.php");
}
}
?>
<form method="post" action="admin_add.php" enctype="multipart/form-
data">
<table class="table">
<tr>
<th>ISBN</th>
<td><input type="text" name="isbn"></td>
</tr>
<tr>
<th>Title</th>
<td><input type="text" name="title" required></td>
</tr>
<tr>
<th>Author</th>
<td><input type="text" name="author" required></td>
</tr>
<tr>
<th>Image</th>
<td><input type="file" name="image"></td>
</tr>
<tr>
<th>Description</th>
<td><textarea name="descr" cols="40"
rows="5"></textarea></td>
</tr>
<tr>
<th>Price</th>
<td><input type="text" name="price" required></td>
</tr>
<tr>
29
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
<th>Publisher</th>
<td><input type="text" name="publisher" required></td>
</tr>
</table>
<input type="submit" name="add" value="Add new book" class="btn
btn-primary">
<input type="reset" value="cancel" class="btn btn-default">
</form>
<br/>
<?php
if(isset($conn)) {mysqli_close($conn);}
require_once "./template/footer.php";
?>
Admin book.php
<?php
session_start();
require_once "./functions/admin.php";
$title = "List book";
require_once "./template/header.php";
require_once "./functions/database_functions.php";
$conn = db_connect();
$result = getAll($conn);
?>
<p class="lead"><a href="admin_add.php">Add new book</a></p>
<a href="admin_signout.php" class="btn btn-primary">Sign out!</a>
<table class="table" style="margin-top: 20px">
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Author</th>
<th>Image</th>
30
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
<th>Description</th>
<th>Price</th>
<th>Publisher</th>
<th> </th>
<th> </th>
</tr>
<?php while($row = mysqli_fetch_assoc($result)){ ?>
<tr>
<td><?php echo $row['book_isbn']; ?></td>
<td><?php echo $row['book_title']; ?></td>
<td><?php echo $row['book_author']; ?></td>
<td><?php echo $row['book_image']; ?></td>
<td><?php echo $row['book_descr']; ?></td>
<td><?php echo $row['book_price']; ?></td>
<td><?php echo getPubName($conn, $row['publisherid']);
?></td>
<td><a href="admin_edit.php?bookisbn=<?php echo
$row['book_isbn']; ?>">Edit</a></td>
<td><a href="admin_delete.php?bookisbn=<?php echo
$row['book_isbn']; ?>">Delete</a></td>
</tr>
<?php } ?>
</table>
<?php
if(isset($conn)) {mysqli_close($conn);}
require_once "./template/footer.php";
?>
31
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
Books.php
<?php
session_start();
$book_isbn = $_GET['bookisbn'];
// connecto database
require_once "./functions/database_functions.php";
$conn = db_connect();
$row = mysqli_fetch_assoc($result);
if(!$row){
echo "Empty book";
exit;
}
$title = $row['book_title'];
require "./template/header.php";
?>
<!-- Example row of columns -->
<p class="lead" style="margin: 25px 0"><a href="books.php">Books</a> >
<?php echo $row['book_title']; ?></p>
<div class="row">
<div class="col-md-3 text-center">
<img class="img-responsive img-thumbnail" src="./bootstrap/img/<?php
echo $row['book_image']; ?>">
</div>
<div class="col-md-6">
<h4>Book Description</h4>
32
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
33
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
Cart.php
<?php
// the shopping cart needs sessions, to start one
/*
Array of session(
cart => array (
book_isbn (get from $_POST['book_isbn']) => number of
books
),
items => 0,
total_price => '0.00'
)
*/
session_start();
require_once "./functions/database_functions.php";
require_once "./functions/cart_functions.php";
// book_isbn got from form post method, change this place later.
if(isset($_POST['bookisbn'])){
$book_isbn = $_POST['bookisbn'];
}
if(isset($book_isbn)){
// new iem selected
34
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
if(!isset($_SESSION['cart'])){
// $_SESSION['cart'] is associative array that bookisbn => qty
$_SESSION['cart'] = array();
$_SESSION['total_items'] = 0;
$_SESSION['total_price'] = '0.00';
}
if(!isset($_SESSION['cart'][$book_isbn])){
$_SESSION['cart'][$book_isbn] = 1;
} elseif(isset($_POST['cart'])){
$_SESSION['cart'][$book_isbn]++;
unset($_POST);
}
}
35
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
$_SESSION['total_items'] = total_items($_SESSION['cart']);
?>
<form action="cart.php" method="post">
<table class="table">
<tr>
<th>Item</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
</tr>
<?php
foreach($_SESSION['cart'] as $isbn => $qty){
$conn = db_connect();
$book =
mysqli_fetch_assoc(getBookByIsbn($conn, $isbn));
?>
<tr>
<td><?php echo $book['book_title'] . " by " .
$book['book_author']; ?></td>
<td><?php echo "$" . $book['book_price']; ?></td>
<td><input type="text" value="<?php echo $qty; ?>"
size="2" name="<?php echo $isbn; ?>"></td>
<td><?php echo "$" . $qty * $book['book_price'];
?></td>
</tr>
<?php } ?>
<tr>
<th> </th>
<th> </th>
<th><?php echo $_SESSION['total_items']; ?></th>
<th><?php echo "$" . $_SESSION['total_price']; ?></th>
</tr>
</table>
36
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
Checkout.php
<?php
// the shopping cart needs sessions, to start one
/*
Array of session(
cart => array (
book_isbn (get from $_GET['book_isbn']) => number of
books
),
items => 0,
total_price => '0.00'
)
*/
session_start();
require_once "./functions/database_functions.php";
// print out header here
$title = "Checking out";
require "./template/header.php";
37
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
<?php } ?>
<div class="form-group">
<label for="name" class="control-label col-md-
4">Name</label>
<div class="col-md-4">
<input type="text" name="name" class="col-md-4"
class="form-control">
</div>
</div>
<div class="form-group">
<label for="address" class="control-label col-md-
4">Address</label>
<div class="col-md-4">
<input type="text" name="address" class="col-md-4"
class="form-control">
</div>
</div>
<div class="form-group">
<label for="city" class="control-label col-md-4">City</label>
<div class="col-md-4">
<input type="text" name="city" class="col-md-4"
class="form-control">
</div>
</div>
<div class="form-group">
<label for="zip_code" class="control-label col-md-4">Zip
Code</label>
<div class="col-md-4">
<input type="text" name="zip_code" class="col-md-4"
class="form-control">
</div>
</div>
<div class="form-group">
<label for="country" class="control-label col-md-
4">Country</label>
39
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
<div class="col-md-4">
<input type="text" name="country" class="col-md-4"
class="form-control">
</div>
</div>
<div class="form-group">
<input type="submit" name="submit" value="Purchase"
class="btn btn-primary">
</div>
</form>
<p class="lead">Please press Purchase to confirm your purchase, or
Continue Shopping to add or remove items.</p>
<?php
} else {
echo "<p class=\"text-warning\">Your cart is empty! Please make sure
you add some books in it!</p>";
}
if(isset($conn)){ mysqli_close($conn); }
require_once "./template/footer.php";
?>
Contact.php
<?php
$title = "Contact";
require_once "./template/header.php";
?>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6 text-center">
<form class="form-horizontal">
<fieldset>
<legend>Contact</legend>
<p class="lead">I’d love to hear from you! Complete
40
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
</form>
</div>
<div class="col-md-3"></div>
</div>
<?php
require_once "./template/footer.php";
?>
Edit books.php
<?php
// if save change happen
if(!isset($_POST['save_change'])){
echo "Something wrong!";
exit;
}
$isbn = trim($_POST['isbn']);
$title = trim($_POST['title']);
$author = trim($_POST['author']);
$descr = trim($_POST['descr']);
$price = floatval(trim($_POST['price']));
$publisher = trim($_POST['publisher']);
require_once("./functions/database_functions.php");
$conn = db_connect();
} else {
header("Location: admin_edit.php?bookisbn=$isbn");
}
?>
Index.php
<?php
session_start();
$count = 0;
// connecto database
$title = "Index";
require_once "./template/header.php";
require_once "./functions/database_functions.php";
$conn = db_connect();
$row = select4LatestBook($conn);
?>
<!-- Example row of columns -->
<p class="lead text-center text-muted">Latest books</p>
<div class="row">
<?php foreach($row as $book) { ?>
<div class="col-md-3">
<a href="book.php?bookisbn=<?php echo $book['book_isbn']; ?>">
<img class="img-responsive img-thumbnail" src="./bootstrap/img/<?php
echo $book['book_image']; ?>">
</a>
</div>
<?php } ?>
</div>
<?php
if(isset($conn)) {mysqli_close($conn);}
require_once "./template/footer.php";
44
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
?>
Publisher.php
<?php
session_start();
require_once "./functions/database_functions.php";
$conn = db_connect();
45
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
}
while ($pubInBook = mysqli_fetch_assoc($result2)){
if($pubInBook['publisherid'] == $row['publisherid']){
$count++;
}
}
?>
<li>
<span class="badge"><?php echo $count; ?></span>
<a href="bookPerPub.php?pubid=<?php echo $row['publisherid'];
?>"><?php echo $row['publisher_name']; ?></a>
</li>
<?php } ?>
<li>
<a href="books.php">List full of books</a>
</li>
</ul>
<?php
mysqli_close($conn);
require "./template/footer.php";
?>
Purchase.php
}
}
require_once "./functions/database_functions.php";
// print out header here
$title = "Purchase";
require "./template/header.php";
// connect database
if(isset($_SESSION['cart']) && (array_count_values($_SESSION['cart']))){
?>
46
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
<table class="table">
<tr>
<th>Item</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
</tr>
<?php
foreach($_SESSION['cart'] as $isbn => $qty){
$conn = db_connect();
$book =
mysqli_fetch_assoc(getBookByIsbn($conn, $isbn));
?>
<tr>
<td><?php echo $book['book_title'] . " by " .
$book['book_author']; ?></td>
<td><?php echo "$" . $book['book_price']; ?></td>
<td><?php echo $qty; ?></td>
<td><?php echo "$" . $qty * $book['book_price']; ?></td>
</tr>
<?php } ?>
<tr>
<th> </th>
<th> </th>
<th><?php echo $_SESSION['total_items']; ?></th>
<th><?php echo "$" . $_SESSION['total_price']; ?></th>
</tr>
<tr>
<td>Shipping</td>
<td> </td>
<td> </td>
<td>20.00</td>
</tr>
<tr>
47
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
48
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
49
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
Testing Objectives
A good test case is one that has a high probability of finding an as-yet
undiscovered error.
There are some limitations for the current system to which solutions can be
provided as a future development:
1. The system is not configured for multi- users at this time. The concept
50
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
51
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
13.0. Conclusion
The Internet has become a major resource in modern business, thus electronic
shopping has gained significance not only from the entrepreneur’s but also from
the customer’s point of view. For the entrepreneur, electronic shopping generates
new business opportunities and for the customer, it makes comparative shopping
possible. As per a survey, most consumers of online stores are impulsive and
usually make a decision to stay on a site within the first few seconds. “Website
design is like a shop interior. If the shop looks poor or like hundreds of other shops
the customer is most likely to skip to the other site”. Hence we have designed the
project to provide the user with easy navigation, retrieval of data and necessary
feedback as much as possible. In this project, the user is provided with an e-
commerce web site that can be used to buy books online. To implement this as a
web application we used PHP as the Technology. PHP (XAMPP) has several
advantages such as enhanced performance, scalability, built- in security and
simplicity. To build any web application using PHP we need a programming
language such as JAVA, HTML # and so on. JAVA SCRIPT was the language
used to build this application. PHP uses MySQL server to interact with the
database as it provides in-memory caching that eliminates the need to contact the
database server frequently and it can easily deploy and maintain an PHP
application. MySQL was used as back-end database since it is one of the most
popular open source databases, and it provides fast data access, easy installation
and simplicity.
A good shopping cart design must be accompanied with user-friendly shopping
cart application logic. It should be convenient for the customer to view the contents
of their cart and to be able to remove or add items to their cart. The shopping cart
application described in this project provides a number of features that are
designed to make the customer more comfortable. This project helps in
understanding the creation of an interactive web page and the technologies used to
implement it. The design of the project which includes Data Model and Process
Model illustrates how the database is built with different tables, how the data is
accessed and processed from the tables. The building of the project has given me a
precise knowledge about how PHP is used to develop a website, how it connects to
the database to access the data and how the data and web pages are modified to
provide the user with a shopping cart application.
52
ONLINE BOOKS SHOPPING 6 TH SEM BCA 2022/23
53