Computer Ecommerce Project
Computer Ecommerce Project
XAVIER’S COLLEGE
Maitighar, Kathmandu
(Affiliated to National Examinations Board)
………………………….
Supervisor
Mr. Jaya Sundar Shilpakar
Department of Computer Science
St. Xavier’s College
Maitighar, Kathmandu, Nepal
………………………….
Head Of Department
Ms. Jamuna Maharjan
Department of Computer Science
St. Xavier’s College
Maitighar, Kathmandu, Nepal
iii
ABSTRACT
This project describes a functional e-commerce website prototype with user
authentication and product management features, built with a React.js frontend
and a PHP backend. The system implements CRUD functionalities for products,
users, and categories, enabling efficient management of the e-commerce platform.
The backend is developed in PHP with MySQL as the database to store information
about users, products, and categories. The front end, built with React.js and
Tailwind CSS, provides an intuitive and responsive user interface for browsing,
purchasing, and managing products.
Key features include:
User Authentication: Secure registration and login for users.
Product Management: Adding, updating, and deleting products and
categories.
Cart System: Users can add products to their cart for purchase.
Although this prototype does not integrate a live payment gateway, the system is
designed to handle product transactions and user interactions in a simulated
environment. The project demonstrates the ability to build a full-stack e-commerce
application, laying the foundation for scalable, enterprise-level systems with
advanced features like live payment integration and real-time inventory management.
iv
ACKNOWLEDGEMENT
The outcome of this project required a lot of guidance and assistance from several
people, and I am extremely fortunate to have received such proper supervision for the
completion of the project. Whatever I have accomplished in this project is solely due
to their instructions and assistance, and I would not forget to express my gratitude to
them. I am indebted to the Department of Computer Science, St. Xavier's College,
Maitighar, for providing me with such an excellent platform for the project. I am
sincerely grateful to the project supervisor and our esteemed Computer Science
lecturer, Mr. Jaya Sundar Shilpakar.I am thankful and fortunate enough to have
received constant encouragement, support, and guidance from them, as they have
helped me in finalizing my project work. I also extend my gratitude to all the
organizations that provided the necessary information for this report.
v
TABLE OF CONTENTS
CERTIFICATE OF APPROVAL.................................................................................iii
ABSTRACT..................................................................................................................iv
ACKNOWLEDGEMENT.............................................................................................v
TABLE OF CONTENTS..............................................................................................vi
LIST OF TABLES.........................................................................................................1
LIST OF FIGURES........................................................................................................2
LIST OF ABBREVIATIONS........................................................................................3
CHAPTER-I: INTRODUCTION...................................................................................4
1.1 Background Information:.................................................................................4
1.2 Statement of the problem:........................................................................4
1.3 Objectives of the Study:...................................................................................4
1.4 Significance of the Research:...........................................................................5
CHAPTER-II: LITERATURE REVIEW......................................................................6
2.1 Introduction......................................................................................................6
2.2 E-commerce Systems and Their Evolution......................................................6
2.3 User Authentication in E-commerce................................................................6
2.4 Database Management in E-commerce............................................................6
2.5 Frontend-Backend Integration in E-commerce................................................7
2.6 Security Considerations in E-commerce..........................................................7
2.7 The Role of Tailwind CSS in Modern E-commerce Design............................8
2.8 Payment Processing in E-commerce................................................................8
2.9 Scalability and Performance Optimization......................................................8
2.10 Conclusion......................................................................................................8
CHAPTER-III: METHODOLOGY.............................................................................10
3.Techniques for Analysis....................................................................................13
CHAPTER- IV: IMPLEMENTATION.......................................................................15
4.1 Designs: The designs, including pseudo-code, algorithm and flowchart are as
follows:.................................................................................................................15
vi
4.1.1 Pseudo code:........................................................................................15
4.1.2 Algorithm:...........................................................................................16
4.2 Development..................................................................................................19
4.2.1 Codes...................................................................................................19
Componets............................................................................................................21
Header.jsx.....................................................................................................21
NavBar.jsx....................................................................................................21
ProductList.jsx.............................................................................................24
SignUp.jsx....................................................................................................25
Cart.jsx.........................................................................................................32
UserAvatar.jsx..............................................................................................35
Backend................................................................................................................36
Initialize.php.........................................................................................................36
Product.php..................................................................................................37
User.php.......................................................................................................42
Read.php.......................................................................................................46
Create.php....................................................................................................48
Delete.php....................................................................................................49
4.3 System Requirements.....................................................................................50
4.3.1 Software Requirements:......................................................................50
4.3.2 Hardware Requirements:.....................................................................51
CHAPTER-V: RESULTS AND OUTPUTS...............................................................52
5.1 Home Page.....................................................................................................52
5.2 Login Page.....................................................................................................54
5.3 Signup Page....................................................................................................55
5.4 Cart page..................................................................................................56
4.3 Database.........................................................................................................57
CHAPTER-VI: CONCLUSION..................................................................................59
6.1 Findings:.........................................................................................................59
6.2 Limitations:....................................................................................................59
vii
6.3 Future Scope:.................................................................................................61
REFERENCES.............................................................................................................62
viii
LIST OF TABLES
Page 10: Gantt Chart
Page 10: Timetable
1
LIST OF FIGURES
Page 13: Flowchart
Page 38: Outputs
Page 39: Outputs
Page 40: OUtputs
Page 41: Outputs
2
LIST OF ABBREVIATIONS
CSS — Cascading Style Sheets
DOM — Document Object Model
HTML — HyperText Markup Language
JS — JavaScript
PDF — Portable Document Format
PHP — Hypertext Preprocessor
3
CHAPTER-I: INTRODUCTION
With the increasing shift toward online shopping, businesses must implement robust
user authentication, efficient product handling, and smooth customer interactions.
However, many developers lack practical experience in designing and developing
such systems, particularly in integrating backend and frontend technologies
effectively.
This gap in understanding makes it difficult for developers to create secure, scalable,
and user-friendly e-commerce solutions. Key challenges include handling user
authentication securely, managing product data efficiently, and ensuring seamless
communication between the frontend and backend.
This project aims to bridge that gap by developing a full-stack e-commerce prototype
with React.js for the frontend and PHP with MySQL for the backend. It serves as both
a functional online store and a learning resource, helping developers understand the
complexities of modern e-commerce application development.
4
1. To develop a secure user authentication system that enables account creation,
login, and user management.
2. To implement a product management feature allowing users to add, update,
delete, and view products.
3. To create a shopping cart system where users can add products, manage their
cart, and proceed to checkout.
4. To design a MySQL database for securely storing user information, product
details, and transaction records.
5. To build an intuitive and responsive frontend using React.js and Tailwind CSS
to enhance the user experience.
5
CHAPTER-II: LITERATURE REVIEW
2.1 Introduction
E-commerce has transformed how businesses and consumers interact, providing a
fast, efficient, and scalable solution for online retailing. The rise of digital
transactions, secure authentication systems, and dynamic product management tools
has contributed significantly to the development of modern e-commerce platforms.
This literature review examines various components of e-commerce, including user
authentication, product management, database integration, and frontend-backend
communication, which are essential for the successful implementation of an e-
commerce system.
Additionally, the review highlights existing technologies such as PHP for backend
processing, MySQL for database management, and React.js for frontend
development. The study aims to establish the importance of security, scalability, and
user experience in designing a functional and effective e-commerce platform.
6
Database management plays a critical role in ensuring the efficient storage and
retrieval of e-commerce data. A well-structured database must support fast queries,
secure transactions, and scalable architecture (Elmasri & Navathe, 2015). MySQL,
being a relational database management system (RDBMS), provides features such as
ACID compliance, indexing, and query optimization, making it a suitable choice for
e-commerce platforms.
A properly designed MySQL database should include:
Users table: Storing user information, login credentials, and account details.
Products table: Managing product listings, stock levels, and pricing.
Orders table: Tracking purchases and user transactions.
Categories table: Organizing products into relevant sections for easy
navigation.
Research indicates that database optimization techniques such as indexing,
query caching, and partitioning can improve system performance by up to
40% (Silberschatz et al., 2020).
7
Research suggests that e-commerce platforms implementing security best
practices reduce cyber attack risks by over 75% (OWASP, 2022).
2.10 Conclusion
This literature review highlights the key components of e-commerce platforms,
focusing on secure user authentication, efficient database management, frontend-
backend integration, and system scalability. By leveraging PHP, MySQL, React.js,
8
and Tailwind CSS, this project provides a functional and scalable prototype for
modern e-commerce applications.
By implementing security best practices, optimizing performance, and ensuring
seamless user experience, this project serves as a practical foundation for future
advancements in online retail and e-commerce system development.
9
CHAPTER-III: METHODOLOGY
Primary Sources:
∙ User feedback collected through surveys and questionnaires during the testing
phase.
∙ Observations of user interactions with the platform to evaluate usability and
functionality.
Secondary Sources:
Tools:
To develop a functional and efficient e-commerce platform, various tools are utilized
for frontend development, backend processing, database management, and
debugging. These tools ensure seamless integration, security, and performance
optimization.
Purpose: Used for structuring and styling the webpage, ensuring a visually
appealing and user-friendly interface.
Implementation:
o HTML (HyperText Markup Language) structures the web pages by
defining elements like buttons, images, text fields, and sections.
o CSS (Cascading Style Sheets) styles these elements to enhance
aesthetic appeal, responsiveness, and usability.
Why it is Important?
o Ensures a consistent layout across different devices.
o Enhances user experience by improving readability and design.
o Facilitates better accessibility for users.
Purpose: Primary text editor for writing, debugging, and testing both frontend
and backend code.
Features Utilized:
10
Syntax highlighting for PHP, JavaScript, and CSS.
o
Integrated debugging tools for error detection.
o
Version control integration (Git) for tracking project changes.
o
Why it is Important?
o Speeds up development with intelligent code suggestions and
debugging.
o Supports multiple extensions to enhance development efficiency.
3. JavaScript
4. MySQL
5. Computer
6. Google
11
Purpose: Used for research, troubleshooting, and documentation access.
Implementation:
o Google Search for resolving coding issues.
o Stack Overflow & GitHub for solutions to common problems.
o MDN Web Docs & W3Schools for JavaScript, CSS, and HTML
references.
Why it is Important?
o Helps in troubleshooting errors and debugging efficiently.
o Provides best practices for security, UI/UX, and performance
optimization.
1. Functional Testing
Purpose: Ensures that every feature performs correctly and meets expected
outputs.
Implementation:
o Testing user authentication (registration, login, logout).
o Verifying product management (adding, deleting, and updating
products).
o Checking subscription management (viewing, selecting, and
modifying plans).
o Validating payment simulation (recording transactions correctly).
Outcome: Identifies and fixes bugs, missing functionalities, and incorrect
responses before deployment.
2. Database Validation
3. Usability Testing
4. Timeline
12
Phase Tasks Timeline
5. Gantt Chart
Day 1-4 5-8 9-12 13-16 17-20 21-24
Phase 1: Planning X
and Requirement
Analysis
Phase 3: Backend X
Development
Phase 4: Frontend X
Development
13
CHAPTER- IV: IMPLEMENTATION
4.1 Designs:
The designs, including pseudo-code, algorithm and flowchart are as follows:
1. BEGIN
2.LAND tot Home Page
3. PROMPT user to Login or Sign Up
4. IF user selects Sign Up, THEN:
1. PROMPT for Name, Email, Password
2. STORE user details in the database
3. DISPLAY "Sign Up Successful! Please Login."
5. IF user selects Login, THEN:
1. PROMPT for Email and Password
2. CHECK if credentials exist in the database
3. IF valid, DISPLAY "Login Successful! Redirecting to Home Page..."
4. ELSE, DISPLAY "Invalid Credentials! Try Again."
6. DISPLAY available products and categories
7. PROMPT user to select a product or category to view
8. DISPLAY selected product or category details
9. IF user adds a product to cart, THEN:
1. ADD product to the shopping cart
2. DISPLAY "Product added to cart!"
10. IF user proceeds to checkout, THEN:
1. PROMPT for shipping details (Address, Contact Information)
2. DISPLAY "Order Summary"
3. DISPLAY "Thank you for your order!"
4. STORE order details in the database
14
11. END
4.1.2 Algorithm:
1. BEGIN
2. DISPLAY "Welcome to the E-Commerce Platform - Sign Up"
3. PROMPT user to input Name, Email, Password
4. VALIDATE input fields:
- Ensure Name is not empty
- Ensure Email is valid and not already in the database
- Ensure Password meets security requirements (e.g., minimum length)
5. IF validation fails, DISPLAY error message and EXIT
6. Encrypt Password for security
7. STORE user details (Name, Email, Encrypted Password) in the database
8. DISPLAY "Sign Up Successful! Please Login."
9. END
15
4.1.3 Flowchart:
16
4.2 Development
The development part of the project includes the main codes required for
the project.
4.2.1 Codes
ReactJs Components
main.jsx
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.jsx'
createRoot(document.getElementById('root')).render(
<StrictMode>
<App />
</StrictMode>,
)
App.jsx
import "./App.css";
import Header from "./components/Header";
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
import ProductList from "./components/ProductList.jsx";
import SignUp from "./components/SignUp.jsx";
import { useEffect, useState } from "react";
import SignIn from "./components/SignIn.jsx";
import Cart from "./components/Cart.jsx";
function App() {
const [user, setuser] = useState({
id: "",
name: "",
17
email: "",
phone_number: "",
address: "",
created_at: "",
});
// usestate to store the cart
const [cart, setcart] = useState([]);
console.log(cart);
// grabbing the user credertial from the local storage only when the app loads .
useEffect(() => {
const userCredentials = JSON.parse(localStorage.getItem("user"));
if (userCredentials) {
setuser(userCredentials);
}
}, []);
console.log(cart);
return (
<Router>
<Header user={user} cart={cart} />
<Routes>
<Route
path="/"
element={<ProductList cart={cart} setcart={setcart} />}
/>
<Route path="/signup" element={<SignUp />} />
<Route path="/signin" element={<SignIn setuser={setuser} />} />
{/* <Route path="/" element={<ProductList addToCart={addToCart} />} />
*/}
<Route path="/cart" element={<Cart cart={cart} setcart={setcart} />} />
{/* <Route path="/checkout" element={<Checkout cartItems={cartItems}
/>} /> */}
18
</Routes>
</Router>
);
}
export default App;
Componets
Header.jsx
NavBar.jsx
19
return (
<div className="min-h-16">
<div className="antialiased bg-gray-100 dark-mode:bg-gray-900">
<div className="w-full text-gray-700 bg-white dark-mode:text-gray-200 dark-
mode:bg-gray-800">
<div className="flex flex-col max-w-screen-xl px-4 mx-auto md:items-center
md:justify-between md:flex-row md:px-6 lg:px-8">
<div className="flex flex-row items-center justify-between p-4">
<Link
to="/"
className="text-lg font-semibold tracking-widest text-gray-900 uppercase
rounded-lg dark-mode:text-white focus:outline-none focus:shadow-outline"
>
Shoppify
</Link>
<button
className="rounded-lg md:hidden focus:outline-none focus:shadow-
outline"
onClick={toggleMenu} // Use the toggle function on click
>
<svg
fill="currentColor"
viewBox="0 0 20 20"
className="w-6 h-6"
>
<path
id="icon-hamburger"
className={!isMenuOpen ? "" : "hidden"}
fillRule="evenodd"
clipRule="evenodd"
></path>
<path
20
id="icon-close"
className={isMenuOpen ? "" : "hidden"}
fillRule="evenodd".293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293
5.707a1 1 0 010-1.414z"
clipRule="evenodd"
></path>
</svg>
</button>
</div>
<nav
className={`flex-col flex-grow ${
isMenuOpen ? "block" : "hidden"
} pb-4 md:pb-0 md:flex md:justify-end md:flex-row`}
>
<Link
to="/cart"
>
Cart
{cart && (
<span className="text-sm font-semibold text-gray-900">
({cart.reduce((prev, curr) => prev + curr.quantity, 0)})
</span>
)}
</Link>
<a
href="#"
>
About
</a>
{user.id && (
<UserAvatar name={user.name} created_at={user.created_at} />
21
)}
{!user.id && (
<>
<Link to="/signup">
Sign up
</Link>
<Link
to="/signin"
>
Sign in
</Link>
</>
)}
</nav></div></div></div>
</div>
);
};
export default Navbar;
ProductList.jsx
// src/components/ProductList.jsx
import { useState, useEffect } from "react";
import axios from "axios";
import ProductCard from "./ProductCard";
const ProductList = ({ cart, setcart }) => {
const [products, setProducts] = useState([]);
useEffect(() => {
axios
.get("http://localhost/CWA/e_commerce/api/read.php") // Replace with your PHP
API URL
.then((response) => {
22
setProducts(response.data.data);
})
.catch((error) => console.error("Error fetching products:", error));
}, []);
// return (
// <div className="product_list">
//
// </div>
// );
return (
<div className="flex items-center justify-center bg-gray-100">
<div className="container mx-auto">
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4
gap-8">
{products.map((product) => (
<ProductCard
key={product.id}
product={product}
cart={cart}
setcart={setcart}
/>
))}
</div>
</div>
</div>
);
};
export default ProductList;
SignUp.jsx
23
// import { auth } from "../firebase";
// import { db } from "../firebase";
import { Link, useNavigate } from "react-router-dom";
function SignUp() {
const [userInfo, setUserInfo] = useState({
email: "",
password: "",
address: "",
name: "",
phone_number: "",
});
const navigate = useNavigate();
const signUpButtonRef = useRef();
function handleChange(event) {
setUserInfo({ ...userInfo, [event.target.name]: event.target.value });
}
async function handleSubmit(event) {
event.preventDefault();
signUpButtonRef.current.setAttribute("disabled", true);
try {
const response = await fetch(
"http://localhost/CWA/e_commerce/api/create_user.php",
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(userInfo),
}
);
// if there existing error in validation
if (!response.ok) {
24
const result = await response.json();
throw new Error(
`HTTP error! Status: ${response.status} + ${result.error}`
);
}
const result = await response.json();
if (result.success) {
setUserInfo({
email: "",
password: "",
address: "",
name: "",
phone_number: "",
});
navigate("/");
} else {
// if the error was in the databse
throw new Error(result.error || "Registration failed.");
}
} catch (error) {
signUpButtonRef.current.removeAttribute("disabled");
// setAlerts({ show: true, error: error.message });
alert(error.message);
}
}
return (
<div className="flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6
lg:px-8">
<div className="max-w-md w-full space-y-8">
<form
className="mt-8 space-y-6"
25
id="signup-form"
onSubmit={handleSubmit}
>
<input type="hidden" name="remember" defaultValue="true" />
<div className="rounded-md shadow-sm -space-y-px flex flex-col gap-3">
<div>
<label htmlFor="name" className="sr-only">
Full name
</label>
<input
id="name"
name="name"
type="text"
required
className="appearance-none rounded-md relative block w-full px-3 py-2
border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none
focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
placeholder="Full name"
value={userInfo.name}
onChange={handleChange}
/>
</div>
<div>
<label htmlFor="email-address" className="sr-only">
Email address
</label>
<input
id="email-address"
name="email"
type="email"
required
26
className="appearance-none rounded-md relative block w-full px-3 py-2
border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none
focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
placeholder="Email address"
value={userInfo.email}
onChange={handleChange}
/>
</div>
<div>
<label htmlFor="address" className="sr-only">
Address
</label>
<input
id="address"
name="address"
type="text"
required
className="appearance-none rounded-md relative block w-full px-3 py-2
border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none
focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
placeholder="Address"
value={userInfo.address}
onChange={handleChange}
/>
</div>
<div>
<label htmlFor="phone_number" className="sr-only">
Phone Number
</label>
<input
id="phone_number"
name="phone_number"
27
type="number"
required
className="appearance-none rounded-md relative block w-full px-3 py-2
border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none
focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
placeholder="Phone number"
value={userInfo.phone_number}
onChange={handleChange}
/>
</div>
<div>
<label htmlFor="password" className="sr-only">
Password
</label>
<input
id="password"
name="password"
type="password"
required
className="appearance-none rounded-md relative block w-full px-3 py-2
border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none
focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
placeholder="Password"
value={userInfo.password}
onChange={handleChange}
/>
</div>
</div>
<div className="flex items-center justify-between">
<div className="flex items-center">
<input
id="remember-me"
28
name="remember-me"
type="checkbox"
className="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-
300 rounded"
/>
<label
htmlFor="remember-me"
className="ml-2 block text-sm text-gray-900"
>
Remember me
</label>
</div>
<div className="text-sm">
<Link
to="/signin"
className="font-medium text-indigo-600 hover:text-indigo-500"
>
Already a user?
</Link>
</div>
</div>
<div>
<button
type="submit"
className="group relative w-full flex justify-center py-2 px-4 border
border-transparent text-sm font-medium rounded-md text-white bg-indigo-600
hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-
indigo-500"
ref={signUpButtonRef}
>
Sign up
</button>
29
</div>
</form>
</div>
</div>
);
}
export default SignUp;
Cart.jsx
30
<div class="mx-auto w-full flex-none lg:max-w-2xl xl:max-w-4xl">
<div class="space-y-6">
{cart.map((product) => (
<SingleCart product={product} />
))}
</div>
</div>
<div class="mx-auto mt-6 max-w-4xl flex-1 space-y-6 lg:mt-0 lg:w-full">
<div class="space-y-4 rounded-lg border border-gray-200 bg-white p-4
shadow-sm dark:border-gray-700 dark:bg-gray-800 sm:p-6">
<p class="text-xl font-semibold text-gray-900 dark:text-white">
Order summary
</p>
<div class="space-y-4">
<div class="space-y-2">
<dl class="flex items-center justify-between gap-4">
<dt class="text-base font-normal text-gray-500 dark:text-gray-400">
Original price
</dt>
<dd class="text-base font-medium text-gray-900 dark:text-white">
${totalPrice}
</dd>
</dl>
<dl class="flex items-center justify-between gap-4">
<dt class="text-base font-normal text-gray-500 dark:text-gray-400">
Savings
</dt>
<dd class="text-base font-medium text-green-600">
-${discount}
</dd>
</dl>
31
</div>
<dl class="flex items-center justify-between gap-4 border-t border-gray-200
pt-2 dark:border-gray-700">
<dt class="text-base font-bold text-gray-900 dark:text-white">
Total
</dt>
<dd class="text-base font-bold text-gray-900 dark:text-white">
${totalPriceAfterDiscount}
</dd>
</dl>
</div>
<a
href="#"
class="flex w-full items-center justify-center rounded-lg bg-primary-700
px-5 py-2.5 text-sm font-medium text-black hover:bg-primary-800 focus:outline-none
focus:ring-4 focus:ring-primary-300 dark:bg-primary-600 dark:hover:bg-primary-700
dark:focus:ring-primary-800"
>
Proceed to Checkout
</a>
<div class="flex items-center justify-center gap-2">
<span class="text-sm font-normal text-gray-500 dark:text-gray-400">
{" "}
or{" "}
</span>
<Link
to="/"
title=""
class="inline-flex items-center gap-2 text-sm font-medium text-primary-
700 underline hover:no-underline dark:text-primary-500"
>
Continue Shopping
32
<svg
class="h-5 w-5"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<path
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M19 12H5m14 0-4 4m4-4-4-4"
/>
</svg>
</Link>
</div>
</div>
</div>
</div>
</div>
</section>
);
}
export default Cart;
UserAvatar.jsx
33
<div className="flex items-center gap-4">
<img
className="w-10 h-10 rounded-full"
src="/imgs/user_avatar.jpg"
alt=""
/>
<div className="font-medium dark:text-white">
<div>{name}</div>
<div className="text-sm text-gray-500 dark:text-gray-400">
Joined in {created_at}
</div>
</div>
</div>
);
}
Backend
Initialize.php
<?php
defined('DS') ? null : define('DS',DIRECTORY_SEPARATOR);
defined('SITE_ROOT') ? null : define('SITE_ROOT', DS . 'xampp' . DS . 'htdocs' .
DS . 'CWA' . DS . 'e_commerce' );
defined('INC_PATH') ? null : define('INC_PATH',SITE_ROOT. DS . 'includes');
defined('CORE_PATH') ? null : define('CORE_PATH',SITE_ROOT. DS . 'core');
// loading the config files
require_once(INC_PATH . DS . 'config.php');
// core classes
require_once(CORE_PATH . DS . 'product.php');
require_once(CORE_PATH . DS . 'user.php');
?>
34
Product.php
<?php
class Product
{ // database stuff
public $conn;
private $table = 'products';
// product properties
public $id;
public $name;
public $img_src;
public $price;
public $description;
public $category_id;
public $category_name;
public $added_at;
// constructor with db connection
public function __construct($db)
{ $this->conn = $db; }
// getting all the products
public function read()
{ // query$query = "SELECT
c.name AS category_name,
p.id,
p.img_src,
p.category_id, -- Fixed typo
p.name,
p.price,
p.description,
p.added_at
35
FROM " . $this->table . " p -- Added space after table name
LEFT JOIN categories c ON p.category_id = c.id
ORDER BY p.added_at DESC";
// prepare the query
$stmt = $this->conn->prepare($query);
// executing the query
$stmt->execute();
return $stmt; }
// getting single product
public function read_single()
{ // query
$query = "SELECT
c.name AS category_name,
p.id,
p.img_src,
p.category_id, -- Fixed typo
p.name,
p.price,
p.description,
p.added_at
FROM " . $this->table . " p -- Added space after table name
LEFT JOIN categories c ON p.category_id = c.id
WHERE p.id = :id";
// prepare the query
$stmt = $this->conn->prepare($query);
// clean up
$this->id = htmlspecialchars(strip_tags($this->id));
// bind id
$stmt->bindParam(':id', $this->id);
// execute the query
36
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
// set post properties
$this->id = $row['id'];
$this->name = $row['name'];
$this->img_src = $row['img_src'];
$this->description = $row['description'];
$this->price = $row['price'];
$this->added_at = $row['added_at'];
$this->category_id = $row['category_id'];
$this->category_name = $row['category_name'];
}
// create product
public function create()
{ // query
// create query
$query = "INSERT INTO
" . $this->table . "
SET
name = :name,
img_src = :img_src,
description = :description,
price = :price,
category_id = :category_id";
// prepare the query
$stmt = $this->conn->prepare($query);
// clean data
$this->name = htmlspecialchars(strip_tags($this->name));
$this->img_src = htmlspecialchars(strip_tags($this->img_src));
$this->description = htmlspecialchars(strip_tags($this->description));
37
$this->price = htmlspecialchars(strip_tags($this->price));
$this->category_id = htmlspecialchars(strip_tags($this->category_id));
// bind data
$stmt->bindParam(':name', $this->name);
$stmt->bindParam(':img_src', $this->img_src);
$stmt->bindParam(':description', $this->description);
$stmt->bindParam(':price', $this->price);
$stmt->bindParam(':category_id', $this->category_id);
// execute the query
if ($stmt->execute()) {
return true;
}
printf("Error: %s.\n", $stmt->error);
return false;
}
// updating the product
public function update()
{
// query
// create query
$query = "UPDATE
" . $this->table . "
SET
name = :name,
img_src = :img_src,
description = :description,
price = :price,
category_id = :category_id
WHERE id = :id";
// prepare the query
38
$stmt = $this->conn->prepare($query);
// clean data
$this->name = htmlspecialchars(strip_tags($this->name));
$this->img_src = htmlspecialchars(strip_tags($this->img_src));
$this->description = htmlspecialchars(strip_tags($this->description));
$this->price = htmlspecialchars(strip_tags($this->price));
$this->category_id = htmlspecialchars(strip_tags($this->category_id));
$this->id = htmlspecialchars(strip_tags($this->id));
// bind data
$stmt->bindParam(':name', $this->name);
$stmt->bindParam(':img_src', $this->img_src);
$stmt->bindParam(':description', $this->description);
$stmt->bindParam(':price', $this->price);
$stmt->bindParam(':category_id', $this->category_id);
$stmt->bindParam(':id', $this->id);
// execute the query
if ($stmt->execute()) {
return true;
}
printf("Error: %s.\n", $stmt->error);
return false;
}
// deleting the product
public function delete() {
// query
$query = "DELETE FROM " . $this->table . " WHERE id = :id";
// prepare the query
$stmt = $this->conn->prepare($query);
// clean data
$this->id = htmlspecialchars(strip_tags($this->id));
39
// bind data
$stmt->bindParam(':id', $this->id);
// execute the query
if ($stmt->execute()) {
return true;
}
// printing the error message
printf("Error: %s.\n", $stmt->error);
return false;
}
}?>
User.php
<?php
class User
{// database stuff
public $conn;
private $table = 'users';
// product properties
public $id;
public $name;
public $email;
public $phone_number;
public $address;
public $password;
public $created_at;
// constructor with db connection
public function __construct($db)
{ $this->conn = $db; }
// getting all the products
40
public function read()
{// query
$query = "SELECT
id,
name,
email,
phone_number,
address,
password,
created_at
FROM " . $this->table;
// prepare the query
$stmt = $this->conn->prepare($query);
// executing the query
$stmt->execute();
return $stmt; }
// getting single product
// getting all the products
public function read_single()
{ // query
$query = "SELECT
id,
name,
email,
phone_number,
address,
password,
created_at
FROM " . $this->table . "
WHERE id = :id";
41
// prepare the query
$stmt = $this->conn->prepare($query);
// clean up
$this->id = htmlspecialchars(strip_tags($this->id));
// bind id
$stmt->bindParam(':id', $this->id);
// execute the query
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
// set post properties
$this->id = $row['id'];
$this->name = $row['name'];
$this->email = $row['email'];
$this->phone_number = $row['phone_number'];
$this->address = $row['address'];
$this->password = $row['password'];
$this->created_at = $row['created_at']; }
// create user
public function create()
{ // query
// create query
$query = "INSERT INTO
" . $this->table . "
SET
name = :name,
email = :email,
phone_number = :phone_number,
address = :address,
password = :password";
// prepare the query
42
$stmt = $this->conn->prepare($query);
// clean data
$this->name = htmlspecialchars(strip_tags($this->name));
$this->email = htmlspecialchars(strip_tags($this->email));
$this->phone_number = htmlspecialchars(strip_tags($this->phone_number));
$this->address = htmlspecialchars(strip_tags($this->address));
$this->password = htmlspecialchars(strip_tags($this->password));
// bind data
$stmt->bindParam(':name', $this->name);
$stmt->bindParam(':email', $this->email);
$stmt->bindParam(':phone_number', $this->phone_number);
$stmt->bindParam(':address', $this->address);
$stmt->bindParam(':password', $this->password);
// execute the query
if ($stmt->execute()) {
return true; }
printf("Error: %s.\n", $stmt->error);
return false; }
// sign
public function signin()
{ $query = "SELECT
id,
name,
email,
phone_number,
address,
password,
created_at
FROM " . $this->table . "
WHERE email = :email";
43
// prepare the query
$stmt = $this->conn->prepare($query);
// clean up
$this->id = htmlspecialchars(strip_tags($this->id));
// bind id
$stmt->bindParam(':email', $this->email);
// execute the query
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
return $row; }}
?>
Read.php
<?php
// header files
header('Access-Control-Allow-Origin:*');
header('Content-Type: application/json');
include_once('../core/initialize.php');
// instantiate post
$product = new Product($db);
// blog product qqury
$result = $product->read();
// get row count
$num = $result->rowCount();
// check if any posts
if ($num > 0) {
$products_arr = array();
$products_arr['data'] = array();
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
extract($row);
44
$post_item = array(
'id' => $id,
'img_src' => $img_src,
'name' => $name,
'description' => $description,
'price' => $price,
'category_id' => $category_id,
'category_name' => $category_name,
'added_at' => $added_at
);
array_push($products_arr['data'], $post_item);
}
// Move JSON encoding outside the loop
echo json_encode($products_arr);
} else {
echo json_encode(array('message' => 'No post found'));
}?>
Readsingle.php
<?php
// header files
header('Access-Control-Allow-Origin:*');
header('Content-Type: application/json');
include_once('../core/initialize.php');
// instantiate post
$product = new Product($db);
$product->id = isset($_GET['id']) ? $_GET['id'] : die();
// read single post
$product->read_single();
// create array
$products_arr = array(
45
'id' => $product->id,
'img_src' => $product->img_src,
'name' => $product->name,
'description' => $product->description,
'price' => $product->price,
'added_at' => $product->added_at,
'category_id' => $product->category_id,
'category_name' => $product->category_name, );
// make json
print_r(json_encode($products_arr));
?> ?>
Create.php
<?php
// header files
header('Access-Control-Allow-Origin:*');
header('Content-Type: application/json');
header('Access-Control-Allow-Methods:POST');
header('Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-
Headers, Authorization, X-Requested-With'); //add authorization later
include_once('../core/initialize.php');
// instantiate post
$product = new Product($db);
// get raw Producted data
$data = json_decode(file_get_contents("php://input"));
// set produc$product properties
$product->name = $data->name;
$product->img_src = $data->img_src;
$product->description = $data->description;
$product->price = $data->price;
$product->category_id = $data->category_id;
46
// create the new produc$product
if ($product->create()) {
echo json_encode(
array('message' => 'Product created successfully.')
);
} else {
echo json_encode(
array('message' => 'Unable to create Product.')
);}?>
Delete.php
<?php
// header files
header('Access-Control-Allow-Origin:*');
header('Content-Type: application/json');
header('Access-Control-Allow-Methods:DELETE');
header('Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-
Headers, Authorization, X-Requested-With'); //add authorization later
include_once('../core/initialize.php');
// instantiate post
$product = new Product($db);
// get raw Producted data
$data = json_decode(file_get_contents("php://input"));
// set post properties
$product->id = $data->id;
// create the new post
if ($product->delete()) {
echo json_encode(
array('message' => 'Product deleted successfully.')
);
} else {
47
echo json_encode(
array('message' => 'Unable to delete Product.')
);
}
?>
a. Operating System: The system is compatible with Windows, macOS, and Linux to
ensure cross-platform accessibility.
b. Web Server: XAMPP is used to set up the local server environment, which
includes Apache, MySQL, and PHP—essential for running the website and managing
the database.
d. Programming Languages:
PHP is used for server-side scripting to handle user sign-ups, logins, and
subscription management.
HTML and CSS are used for front-end design to ensure an intuitive user
experience.
e. IDE/Editor: Visual Studio Code (VS Code) is used for writing and editing the
code.
f. Web Browser: The system is tested and works on modern web browsers such as
Google Chrome, Mozilla Firefox, and Microsoft Edge.
48
4.3.2 Hardware Requirements:
The hardware requirements for the system are minimal, as the web application is
designed to run smoothly on most modern personal computers. The requirements
include:
a. Processor: A modern processor (minimum 1.6 GHz) to ensure smooth execution of
the local server and web application.
b. RAM: A minimum of 4GB RAM is required to run the XAMPP server
environment and handle multiple web browser tabs during development and testing.
c. Storage: At least 1 GB of free disk space is recommended for installing XAMPP,
storing project files, and managing database records.
d. Network: An internet connection is required for downloading necessary software
packages (XAMPP, Visual Studio Code, etc.) and for testing the application on the
local network.
These software and hardware components ensure that the application operates
optimally during both development and usage.
49
CHAPTER-V: RESULTS AND OUTPUTS
5.1 Home Page
50
51
5.2 Login Page
52
5.3 Signup Page
53
5.4 Cart page
54
4.3 Database
55
56
CHAPTER-VI: CONCLUSION
6.1 Findings:
These findings demonstrate the core functionalities and the overall effectiveness of
your e-commerce platform in providing a secure, intuitive, and reliable shopping
experience.
6.2 Limitations:
57
2. Limited User Roles:
The system currently supports only basic user functionality for registration and
login. It does not include different user roles such as admin for managing
products, users, or subscriptions. This restricts the ability to have a fully
functional backend that can handle diverse access levels and permissions.
3. Scalability Concerns:
The project is designed for a smaller-scale e-commerce platform. It lacks
advanced scalability features, such as the ability to handle a large number of
concurrent users or an extensive product catalog. This could pose challenges if
the platform is expanded to support more users and products.
4. Basic Security Features:
While the project uses some security features like encrypted password storage,
it lacks advanced security measures such as two-factor authentication (2FA),
session timeout, or protection against attacks like SQL injection. These
features would be important for a production-level application.
5. No Real-time Features:
The platform does not include real-time features such as live chat, order
tracking, or real-time updates of product availability. This limits the user
experience, especially for users who expect instant notifications or updates
related to their orders and subscriptions.
These limitations highlight areas where the system could be expanded or improved to
meet the requirements of a fully functional, scalable e-commerce platform.
58
6.3 Future Scope:
59
REFERENCES
[1] React Documentation. (2024). Home. React. https://react.dev/
[2] Tailwind CSS Documentation. (2024). Home. Tailwind CSS.
https://tailwindcss.com/docs
[3] PHP Manual. (2024). Home. PHP. https://www.php.net/manual/en/
[4] MySQL Documentation. (2024). Home. MySQL. https://dev.mysql.com/doc/
[5] Axios GitHub Repository. (2024). Home. Axios. https://github.com/axios/axios
60