/your-project-name
|-- admin/
| |-- index.php
| |-- login.php
| |-- logout.php
| |-- orders.php
| |-- products.php
| |-- includes/
| |-- header.php
| |-- footer.php
| `-- auth_check.php
|-- assets/
| |-- css/
| | `-- style.css
| `-- images/
| |-- (add your product/category images here)
| `-- logo.png
|-- includes/
| |-- header.php
| |-- footer.php
| `-- db.php
|-- index.php
|-- products.php
|-- product_details.php
|-- categories.php
|-- about.php
|-- contact.php
|-- cart.php
|-- cart_actions.php
|-- checkout.php
|-- process_order.php
|-- thankyou.php
`-- contact_handler.php
Css File code
/* A simple dark theme enhancement */
.product-card {
transition: transform .2s ease-in-out, box-shadow .2s ease-in-out;
.product-card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 20px rgba(0,0,0,0.4);
.hero-carousel-item {
height: 60vh;
min-height: 400px;
background-size: cover;
background-position: center;
.hero-carousel-item .container {
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
color: white;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
checkout.php```php
<?php
include 'includes/header.php';
// Redirect to home if cart is empty
if (empty($_SESSION['cart'])) {
header('Location: index.php');
exit;
$cart_items = [];
$subtotal = 0;
$product_ids = array_keys($_SESSION['cart']);
$placeholders = implode(',', array_fill(0, count($product_ids), '?'));
$stmt = $db->prepare("SELECT * FROM products WHERE id IN ($placeholders)");
$stmt->execute($product_ids);
while ($product = $stmt->fetch(PDO::FETCH_ASSOC)) {
$quantity = $_SESSION['cart'][$product['id']];
$subtotal += $product['price'] * $quantity;
$cart_items[] = $product;
?>
<div class="row g-5">
<!-- Order Summary -->
<div class="col-md-5 col-lg-4 order-md-last">
<h4 class="d-flex justify-content-between align-items-center mb-3">
<span class="text-primary">Your cart</span>
<span class="badge bg-primary rounded-pill"><?= count($cart_items) ?></span>
</h4>
<ul class="list-group mb-3">
<?php foreach ($cart_items as $item): ?>
<li class="list-group-item d-flex justify-content-between lh-sm">
<div>
<h6 class="my-0"><?= htmlspecialchars($item['name']) ?></h6>
<small class="text-body-secondary">Quantity: <?= $_SESSION['cart'][$item['id']] ?></small>
</div>
<span class="text-body-secondary">$<?= number_format($item['price'] * $_SESSION['cart'][$item['id']],
2) ?></span>
</li>
<?php endforeach; ?>
<li class="list-group-item d-flex justify-content-between">
<span>Total (USD)</span>
<strong>$<?= number_format($subtotal, 2) ?></strong>
</li>
</ul>
</div>
<!-- Checkout Form -->
<div class="col-md-7 col-lg-8">
<h4 class="mb-3">Billing address</h4>
<form action="process_order.php" method="post" class="needs-validation" novalidate>
<div class="row g-3">
<div class="col-12">
<label for="fullName" class="form-label">Full name</label>
<input type="text" class="form-control" id="fullName" name="fullName" required>
<div class="invalid-feedback">Valid full name is required.</div>
</div>
<div class="col-12">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" name="email" required>
<div class="invalid-feedback">Please enter a valid email address for shipping updates.</div>
</div>
<div class="col-12">
<label for="address" class="form-label">Address</label>
<input type="text" class="form-control" id="address" name="address" required>
<div class="invalid-feedback">Please enter your shipping address.</div>
</div>
</div>
<hr class="my-4">
<h4 class="mb-3">Payment</h4>
<div class="my-3">
<p class="lead">For demonstration purposes, no real payment is processed. Clicking "Place
Order" will simulate a successful transaction.</p>
</div>
<hr class="my-4">
<button class="w-100 btn btn-primary btn-lg" type="submit">Place Order</button>
</form>
</div>
</div>
<script>
// Bootstrap validation script
(function () {
'use strict'
var forms = document.querySelectorAll('.needs-validation')
Array.prototype.slice.call(forms)
.forEach(function (form) {
form.addEventListener('submit', function (event) {
if (!form.checkValidity()) {
event.preventDefault()
event.stopPropagation()
form.classList.add('was-validated')
}, false)
})
})()
</script>
<?php include 'includes/footer.php'; ?>
Admin/include/footer
</div> <!-- closing container -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Admin/include/auth
<?php
// This check is included at the top of every secure admin page
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
header('Location: login.php');
exit;
?>
Admin/index(Dashboard)
<?php include 'includes/header.php'; ?>
<h1>Dashboard</h1>
<p>Welcome, <?= htmlspecialchars($_SESSION['admin_username']) ?>!</p>
<hr>
<div class="row">
<div class="col-md-6">
<div class="card">
<div class="card-body">
<h5 class="card-title">Manage Products</h5>
<p class="card-text">Add, edit, or delete products from your store.</p>
<a href="products.php" class="btn btn-primary">Go to Products</a>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card">
<div class="card-body">
<h5 class="card-title">View Orders</h5>
<p class="card-text">Review customer orders and details.</p>
<a href="orders.php" class="btn btn-primary">Go to Orders</a>
</div>
</div>
</div>
</div>
<?php include 'includes/footer.php'; ?>
Config.php
<?php
$host = 'localhost';
$db_name = 'ecommerce_db';
$username = 'root'; // Or your DB username
$password = ''; // Or your DB password
try {
$db = new PDO("mysql:host=$host;dbname=$db_name;charset=utf8", $username, $password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
exit;
?>
Includes/db.php
<?php
$host = 'localhost';
$db_name = 'ecommerce_db';
$username = 'root'; // Or your DB username
$password = ''; // Or your DB password
try {
$db = new PDO("mysql:host=$host;dbname=$db_name;charset=utf8", $username, $password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
exit;
?>