├── 00_documentation.md
├── 01_databaseSetup.md
├── 02_registrationPageSetup.md
├── 03_loginPageSetup.md
├── 04_logoutPageSetup.md
├── 05_indexPageSetup.md
├── 06_cartPageSetup.md
├── 07_adminLoginPageSetup.md
├── 08_adminLogoutPageSetup.md
├── 09_adminDashboardPageSetup.md
├── 10_adminManageProductsPageSetup.md
├── 11_adminAddProductPageSetup.md
├── admin
├── add_product.php
├── dashboard.php
├── login.php
├── logout.php
└── manage_products.php
├── css
└── style.css
├── images
├── cart-icon.png
├── product1.jpg
├── product2.jpg
├── product3.jpg
├── product4.jpg
└── product5.png
├── includes
└── db.php
├── index.php
└── pages
├── cart.php
├── login.php
├── logout.php
└── register.php
/00_documentation.md:
--------------------------------------------------------------------------------
1 | ### **Project Overview**
2 | This e-commerce platform is designed for **Customers** and **Admins** to handle shopping and management functionalities. Below are concise, sectioned explanations for each part of the project.
3 |
4 | ---
5 |
6 | ### **1. User Section**
7 | This section explains how users interact with the website.
8 |
9 | #### **1.1. How can users register on the platform?**
10 | - **Answer**: Users can create an account on the `register.php` page by providing their name, email, and password. This allows them to access personalized features like the shopping cart.
11 |
12 | #### **1.2. How can users log in and log out?**
13 | - **Login**: Users log in on the `login.php` page using their email and password.
14 | - **Logout**: The `logout.php` page ends the session, ensuring user data is secure.
15 |
16 | #### **1.3. How can users view products?**
17 | - **Answer**: All products are displayed on the homepage (`index.php`). Users can see product names, prices, descriptions, and images.
18 |
19 | #### **1.4. How can users add products to their cart?**
20 | - **Answer**: On the `index.php` page, users click "Add to Cart" to save items. The system records these items in the cart for the logged-in user.
21 |
22 | #### **1.5. How can users manage their cart?**
23 | - **Answer**: The `cart.php` page lets users view, update, or remove items from their cart. It also shows the total cost of selected products.
24 |
25 | ---
26 |
27 | ### **2. Admin Section**
28 | This section explains how admins manage the platform.
29 |
30 | #### **2.1. How do admins log in and log out?**
31 | - **Login**: Admins log in via `admin/login.php` using their credentials.
32 | - **Logout**: The `admin/logout.php` page ends the admin session securely.
33 |
34 | #### **2.2. What is the admin dashboard?**
35 | - **Answer**: The `admin/dashboard.php` page provides a control panel with options to add, edit, and delete products.
36 |
37 | #### **2.3. How do admins add products?**
38 | - **Answer**: The `admin/add_product.php` page allows admins to add new products by filling out a form with product details and uploading an image.
39 |
40 | #### **2.4. How do admins manage products?**
41 | - **Answer**: The `admin/manage_products.php` page shows all products in a table with options to:
42 | - Edit product details.
43 | - Delete products from the store.
44 |
45 | ---
46 |
47 | ### **3. Database Section**
48 | This section explains how the database is structured.
49 |
50 | #### **3.1. What does the users table do?**
51 | - **Answer**: The `users` table stores information about all users (customers and admins):
52 | - Usernames, emails, hashed passwords.
53 | - A `role` field to differentiate between customers (`user`) and admins (`admin`).
54 |
55 | #### **3.2. What does the products table do?**
56 | - **Answer**: The `products` table contains product details:
57 | - Names, prices, descriptions, and image filenames.
58 |
59 | #### **3.3. What does the cart table do?**
60 | - **Answer**: The `cart` table keeps track of items added to users' carts:
61 | - Links users to products and stores the quantity of each item.
62 |
63 | ---
64 |
65 | ### **4. Flow of the Website**
66 | This section explains the flow of user actions.
67 |
68 | #### **4.1. What happens when a user registers?**
69 | - **Answer**: The system validates the input, hashes the password, and saves the user data in the `users` table.
70 |
71 | #### **4.2. What happens when a user logs in?**
72 | - **Answer**: The system verifies the email and password, then starts a session to allow personalized access.
73 |
74 | #### **4.3. What happens when a product is added to the cart?**
75 | - **Answer**: The system saves the product details in the `cart` table, linked to the logged-in user's ID.
76 |
77 | #### **4.4. What happens when an admin adds a product?**
78 | - **Answer**: The system uploads the product image, saves the product details in the `products` table, and displays it on the homepage.
79 |
80 | #### **4.5. What happens when an admin deletes a product?**
81 | - **Answer**: The system removes the product entry from the `products` table, making it unavailable on the website.
82 |
83 | ---
84 |
85 | ### **5. Security Measures**
86 | This section explains how the website ensures security.
87 |
88 | #### **5.1. How are passwords secured?**
89 | - **Answer**: Passwords are hashed using `password_hash()` before being stored in the database.
90 |
91 | #### **5.2. How is session management handled?**
92 | - **Answer**: Sessions track logged-in users (`$_SESSION['user_id']` for customers, `$_SESSION['admin_id']` for admins) to restrict access to sensitive pages.
93 |
94 | #### **5.3. How is admin access secured?**
95 | - **Answer**: Admin login checks the `role` field in the `users` table to ensure only admins can access the control panel.
96 |
97 | ---
98 |
99 | ### How to Use This Guide
100 | Follow the sections to understand:
101 | - How users and admins interact with the platform.
102 | - How the database stores and retrieves data.
103 | - The flow of actions across the website.
104 |
105 | For detailed implementation, refer to the individual PHP files for each feature. Let me know if this structure works for you!
106 |
--------------------------------------------------------------------------------
/01_databaseSetup.md:
--------------------------------------------------------------------------------
1 | ### Step-by-Step Documentation for Database Setup
2 |
3 |
4 | #### Step 1: Creating the Database
5 | 1. Open **phpMyAdmin** or any database management tool.
6 | 2. Create a new database named `ecommerce`.
7 | 3. Run the following SQL commands to create the necessary tables:
8 |
9 | **Cart Table**
10 | ```sql
11 | CREATE TABLE cart (
12 | id INT AUTO_INCREMENT PRIMARY KEY,
13 | user_id INT NOT NULL,
14 | product_id INT NOT NULL,
15 | quantity INT NOT NULL,
16 | created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
17 | updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
18 | );
19 | ```
20 |
21 | **Products Table**
22 | ```sql
23 | CREATE TABLE products (
24 | id INT AUTO_INCREMENT PRIMARY KEY,
25 | name VARCHAR(255) NOT NULL,
26 | price DECIMAL(10, 2) NOT NULL,
27 | description TEXT,
28 | image VARCHAR(255),
29 | created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
30 | );
31 | ```
32 |
33 | **Users Table**
34 | ```sql
35 | CREATE TABLE users (
36 | id INT AUTO_INCREMENT PRIMARY KEY,
37 | username VARCHAR(50) NOT NULL,
38 | email VARCHAR(100) NOT NULL UNIQUE,
39 | password VARCHAR(255) NOT NULL,
40 | created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
41 | role ENUM('user', 'admin') DEFAULT 'user'
42 | );
43 | ```
44 |
45 | ---
46 |
47 | #### Step 2: Setting Up `db.php`
48 | 1. Create a folder named `includes` in your project directory.
49 | 2. Inside this folder, create a file named `db.php`.
50 | 3. Add the following code:
51 |
52 | **`db.php`**
53 | ```php
54 | setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
63 | } catch (PDOException $e) {
64 | echo "Connection failed: " . $e->getMessage();
65 | }
66 | ?>
67 | ```
68 |
69 | **Explanation**:
70 | - This script uses the **PDO (PHP Data Objects)** method for connecting to the database.
71 | - If the connection fails, an error message will be displayed.
72 |
73 | ---
74 |
75 | #### Step 3: Testing the Database Connection
76 | 1. Create a new file named `test_db.php` in the root folder.
77 | 2. Add the following code to test the connection:
78 |
79 | **`test_db.php`**
80 | ```php
81 |
90 | ```
91 |
92 | 3. Access `http://localhost/ecommerce/test_db.php` in your browser.
93 | 4. Ensure the message **"Database connected successfully!"** is displayed.
94 |
95 | ---
96 |
97 | ### Next Steps
98 | Once the database is set up:
99 | 1. Move to the **Registration Page (`register.php`)** so users can create accounts.
100 | 2. Build the **Login Page (`login.php`)** to authenticate users.
101 | 3. Proceed to dynamic pages like `index.php`.
102 |
--------------------------------------------------------------------------------
/02_registrationPageSetup.md:
--------------------------------------------------------------------------------
1 | ### Step-by-Step Documentation for the Registration Page
2 |
3 | Below is the updated and aligned documentation for creating the `register.php` page, incorporating the actual code.
4 |
5 | ---
6 |
7 | #### Step 1: Create the `register.php` File
8 | 1. Inside the `pages` folder, create a file named `register.php`.
9 |
10 | ---
11 |
12 | #### Step 2: Structure the HTML Form
13 | Add the following code to create the registration form:
14 |
15 | **HTML Form for Registration**
16 | ```php
17 |
18 |
19 |
20 |
21 |
22 | Register
23 |
82 |
83 |
84 |
85 |
Register
86 |
93 |
94 |
= htmlspecialchars($error_message); ?>
95 |
96 |
97 |
98 |
99 | ```
100 |
101 | ---
102 |
103 | #### Step 3: Add PHP Logic for Registration
104 | Add this PHP script at the top of the file to handle user registration:
105 |
106 | **PHP Script for Handling Registration**
107 | ```php
108 | prepare("SELECT * FROM users WHERE email = ?");
119 | $stmt->execute([$email]);
120 | $user = $stmt->fetch(PDO::FETCH_ASSOC);
121 |
122 | if ($user) {
123 | echo "";
124 | } else {
125 | // Insert new user
126 | $stmt = $conn->prepare("INSERT INTO users (email, password, role) VALUES (?, ?, ?)");
127 | $stmt->execute([$email, $password, $role]);
128 |
129 | // Log the user in after successful registration
130 | $_SESSION['user_id'] = $conn->lastInsertId();
131 | header("Location: ../index.php"); // Redirect to the homepage
132 | exit();
133 | }
134 | }
135 | ?>
136 | ```
137 |
138 | ---
139 |
140 | #### Step 4: Test the Registration Page
141 | 1. Start your local server.
142 | 2. Navigate to `http://localhost/ecommerce/pages/register.php`.
143 | 3. Register using an email and password.
144 | 4. Check the `users` table in your database to ensure the new user has been added.
145 |
146 | ---
147 |
148 | ### Next Steps
149 | 1. Build the **Login Page (`login.php`)** for user authentication.
150 | 2. Implement session management to maintain user sessions.
151 |
--------------------------------------------------------------------------------
/03_loginPageSetup.md:
--------------------------------------------------------------------------------
1 | ### Step-by-Step Documentation for the Login Page
2 |
3 | Below is the aligned and updated documentation for creating the `login.php` page, based on the actual code.
4 |
5 | ---
6 |
7 | #### Step 1: Create the `login.php` File
8 | 1. Inside the `pages` folder, create a file named `login.php`.
9 |
10 | ---
11 |
12 | #### Step 2: Structure the HTML Form
13 | Add the following code to create the login form:
14 |
15 | **HTML Form for Login**
16 | ```php
17 |
18 |
19 |
20 |
21 |
22 | Login
23 |
82 |
83 |
84 |
85 |
Login
86 |
93 |
94 |
= htmlspecialchars($error_message); ?>
95 |
96 |
97 |
98 |
99 | ```
100 |
101 | ---
102 |
103 | #### Step 3: Add PHP Logic for Login
104 | Include this PHP script at the top of the file to handle user login requests:
105 |
106 | **PHP Script for Handling Login**
107 | ```php
108 | prepare("SELECT * FROM users WHERE email = ?");
118 | $stmt->execute([$email]);
119 | $user = $stmt->fetch(PDO::FETCH_ASSOC);
120 |
121 | if ($user && password_verify($password, $user['password'])) {
122 | // Successful login
123 | $_SESSION['user_id'] = $user['id']; // Store user ID in session
124 | header("Location: ../index.php"); // Redirect to the main page
125 | exit();
126 | } else {
127 | // Invalid login
128 | $error_message = "Invalid email or password.";
129 | }
130 | }
131 | ?>
132 | ```
133 |
134 | ---
135 |
136 | #### Step 4: Test the Login Page
137 | 1. Start your local server.
138 | 2. Navigate to `http://localhost/ecommerce/pages/login.php`.
139 | 3. Use the credentials of a registered user to log in.
140 | 4. Verify successful login:
141 | - Users are redirected to the homepage.
142 | - Invalid credentials show an error message.
143 |
144 | ---
145 |
146 | ### Next Steps
147 | 1. Implement the **Logout System** (`logout.php`) to allow users to securely log out.
148 | 2. Build the **Index Page** (`index.php`).
149 |
150 |
--------------------------------------------------------------------------------
/04_logoutPageSetup.md:
--------------------------------------------------------------------------------
1 | ### Step-by-Step Documentation for the Logout Page
2 |
3 | Below is the aligned and concise guide for implementing the `logout.php` page.
4 |
5 | ---
6 |
7 | #### Step 1: Create the `logout.php` File
8 | 1. Inside the `pages` folder, create a file named `logout.php`.
9 |
10 | ---
11 |
12 | #### Step 2: Add PHP Logic to Destroy the Session
13 | Add the following PHP code to handle the logout functionality:
14 |
15 | ```php
16 |
27 | ```
28 |
29 | **Explanation**:
30 | - `session_start()`: Initializes the session.
31 | - `session_unset()`: Frees all session variables.
32 | - `session_destroy()`: Completely terminates the session.
33 | - `header('Location: login.php')`: Redirects the user to the login page after the session ends.
34 |
35 | ---
36 |
37 | #### Step 3: Add a Logout Link to Other Pages
38 | To ensure users can log out from anywhere, add a logout link to the navigation bar on user-facing pages like `index.php`:
39 |
40 | ```html
41 |
42 | ```
43 |
44 | ---
45 |
46 | #### Step 4: Test the Logout Page
47 | 1. Log in as a user on your site.
48 | 2. Navigate to `http://localhost/ecommerce/pages/logout.php`.
49 | 3. Confirm the following:
50 | - The session is destroyed (e.g., you are logged out).
51 | - You are redirected to the login page.
52 | - Attempting to access a protected page (e.g., `index.php`) after logging out redirects you to `login.php` if session checks are implemented.
53 |
54 | ---
55 |
56 | ### Next Steps
57 | Now that the logout functionality is implemented, the core user management system (registration, login, logout) is complete. Next, we can move to:
58 | 1. **Home Page (`index.php`)** for displaying products.
59 |
--------------------------------------------------------------------------------
/05_indexPageSetup.md:
--------------------------------------------------------------------------------
1 | ### Step-by-Step Documentation for the Home Page (`index.php`)
2 |
3 | ---
4 |
5 | #### 1. Create the `index.php` File
6 | - Place this file in the root directory.
7 | - Add the following HTML structure with navigation links and a container for products:
8 |
9 | ```php
10 |
11 |
12 |
13 |
14 |
15 | Online Store
16 |
17 |
18 |
19 |
20 |
21 |
Welcome to Our Store
22 |
33 |
34 |
35 |
36 |
37 |
Products
38 |
39 |
40 |
41 |
42 |
43 |
46 |
47 |
48 | ```
49 |
50 | ---
51 |
52 | #### 2. Add PHP Logic to Fetch and Display Products
53 | Insert the following PHP code at the top of the file:
54 |
55 | ```php
56 | query("SELECT * FROM products");
62 | $products = $stmt->fetchAll(PDO::FETCH_ASSOC);
63 | ?>
64 | ```
65 |
66 | In the `
52 |
53 | ```
54 |
55 | ---
56 |
57 | #### Step 3: Handle Cart Updates
58 | Add functionality to update quantities and remove items:
59 |
60 | - **Update Quantity:**
61 | ```php
62 | if (isset($_POST['update_quantity'])) {
63 | $product_id = $_POST['product_id'];
64 | $quantity = (int)$_POST['quantity'];
65 | $stmt = $conn->prepare("UPDATE cart SET quantity = ? WHERE user_id = ? AND product_id = ?");
66 | $stmt->execute([$quantity, $user_id, $product_id]);
67 | }
68 | ```
69 |
70 | - **Remove Item:**
71 | ```php
72 | if (isset($_POST['remove_from_cart'])) {
73 | $product_id = $_POST['product_id'];
74 | $stmt = $conn->prepare("DELETE FROM cart WHERE user_id = ? AND product_id = ?");
75 | $stmt->execute([$user_id, $product_id]);
76 | }
77 | ```
78 |
79 | ---
80 |
81 | #### Step 4: Styling
82 | Add CSS to style the cart page:
83 | ```css
84 | .cart-container {
85 | max-width: 800px;
86 | margin: 20px auto;
87 | padding: 20px;
88 | background: #f9f9f9;
89 | border: 1px solid #ddd;
90 | border-radius: 8px;
91 | }
92 | ```
93 |
94 | ---
95 |
96 | #### Step 5: Test the Cart Page
97 | 1. Log in as a user.
98 | 2. Add items to the cart from the product page.
99 | 3. Verify items are displayed correctly.
100 | 4. Check quantity updates and removal functionality.
101 |
102 | ---
103 |
104 | Next Step is Admin Dashboard Pages
105 |
--------------------------------------------------------------------------------
/07_adminLoginPageSetup.md:
--------------------------------------------------------------------------------
1 |
2 | ### Step-by-Step Documentation for Admin Login Page (`admin/login.php`)
3 |
4 | ---
5 |
6 | #### Purpose
7 | The **Admin Login Page** authenticates administrators, granting access to the admin dashboard.
8 |
9 | ---
10 |
11 | #### 1. PHP Logic for Authentication
12 | The PHP code at the top handles login functionality:
13 |
14 | ```php
15 | prepare("SELECT * FROM users WHERE email = ? AND role = 'admin'");
25 | $stmt->execute([$email]);
26 | $user = $stmt->fetch(PDO::FETCH_ASSOC);
27 |
28 | if ($user && password_verify($password, $user['password'])) {
29 | // Start admin session and redirect to dashboard
30 | $_SESSION['admin_id'] = $user['id'];
31 | header("Location: dashboard.php");
32 | exit();
33 | } else {
34 | echo "
Invalid credentials or not an admin.
";
35 | }
36 | }
37 | ?>
38 | ```
39 |
40 | **Key Features:**
41 | - Validates that the `email` belongs to an admin.
42 | - Verifies the password using `password_verify()`.
43 | - Starts a session for authenticated admins.
44 | - Redirects to the `dashboard.php` page upon successful login.
45 |
46 | ---
47 |
48 | #### 2. HTML Form for Login
49 | This is the front-end structure for the admin login page:
50 |
51 | ```html
52 |
53 |
54 |
55 |
56 |
57 | Admin Login
58 |
104 |
105 |
106 |
107 |
108 |
Admin Login
109 |
118 |
119 |
120 |
121 |
122 | ```
123 |
124 | **Features:**
125 | - The form uses `POST` to securely submit credentials.
126 | - Fields include `email` and `password`.
127 |
128 | ---
129 |
130 | #### 3. Test the Admin Login Page
131 | 1. Ensure the `users` table has an admin user (`role = 'admin'`).
132 | 2. Open the page at `http://localhost/ecommerce/admin/login.php`.
133 | 3. Test login with valid and invalid admin credentials.
134 |
135 | ---
136 |
137 | ### Next Step
138 | The next page is **Admin Logout (`admin/logout.php`)** to securely end admin sessions. Let’s proceed!
139 |
--------------------------------------------------------------------------------
/08_adminLogoutPageSetup.md:
--------------------------------------------------------------------------------
1 | ### **1. Why There is No Admin Register Page**
2 | An **Admin Register Page** is typically excluded in secure systems for the following reasons:
3 |
4 | 1. **Security Concerns**:
5 | - Allowing anyone to register as an admin could expose the system to unauthorized access.
6 | - Admin creation is restricted to superusers or developers who have direct access to the database or backend.
7 |
8 | 2. **Controlled Access**:
9 | - Admins are added manually by authorized personnel (e.g., via a secure backend or database query).
10 | - This ensures only trusted individuals are granted administrative privileges.
11 |
12 | 3. **Simpler Role Management**:
13 | - Using a `role` field in the `users` table (`user` vs `admin`) simplifies user management without requiring separate registration flows.
14 |
15 | ---
16 |
17 | ### **2. Adding an Admin User to the Database**
18 |
19 | To add an admin user manually in the database, follow these steps:
20 |
21 | #### Using **phpMyAdmin** or SQL Console:
22 | 1. **Insert Admin User**:
23 | Run the following SQL query:
24 | ```sql
25 | INSERT INTO users (username, email, password, role, created_at)
26 | VALUES ('Admin Name', 'admin@example.com', '', 'admin', NOW());
27 | ```
28 | Replace:
29 | - `'Admin Name'` with the admin's name.
30 | - `'admin@example.com'` with the admin's email.
31 | - `''` with the hashed password.
32 |
33 | #### Example Query:
34 | ```sql
35 | INSERT INTO users (username, email, password, role, created_at)
36 | VALUES ('Super Admin', 'admin@ecommerce.com', '$2y$10$abcdefghijk1234567890LMNOPQRSTUVWXyz12345678', 'admin', NOW());
37 | ```
38 |
39 | 2. **Verify the Inserted Admin**:
40 | Query the `users` table to confirm the new admin user:
41 | ```sql
42 | SELECT * FROM users WHERE role = 'admin';
43 | ```
44 |
45 | ---
46 |
47 | ### **3. Next: Admin Logout Page**
48 |
49 | ### Step-by-Step Documentation for Admin Logout Page (`admin/logout.php`)
50 |
51 | ---
52 |
53 | #### Purpose
54 | The **Admin Logout Page** securely ends the admin session and redirects the user to the admin login page.
55 |
56 | ---
57 |
58 | #### Code Breakdown
59 | The code for `admin/logout.php` is simple yet effective:
60 |
61 | ```php
62 |
69 | ```
70 |
71 | ---
72 |
73 | #### How It Works
74 | 1. **Start the Session**:
75 | - The session is initiated with `session_start()` to access and manage session variables.
76 |
77 | 2. **Unset All Variables**:
78 | - `session_unset()` removes all session variables, ensuring no leftover data persists.
79 |
80 | 3. **Destroy the Session**:
81 | - `session_destroy()` completely terminates the session, effectively logging out the admin.
82 |
83 | 4. **Redirect**:
84 | - After ending the session, the admin is redirected to `login.php` using `header("Location: login.php");`.
85 |
86 | ---
87 |
88 | #### Implementation Steps
89 | 1. Place the `logout.php` file in the `admin/` folder.
90 | 2. Add a **Logout Link** to the admin dashboard (`dashboard.php`):
91 | ```html
92 |
93 | ```
94 |
95 | ---
96 |
97 | #### Testing the Logout Page
98 | 1. Log in as an admin.
99 | 2. Navigate to `http://localhost/ecommerce/admin/logout.php`.
100 | 3. Confirm:
101 | - The session is ended.
102 | - You are redirected to the admin login page.
103 | - Attempting to access the dashboard (`dashboard.php`) redirects to the login page if session checks are implemented.
104 |
105 | ---
106 |
107 | Next proceed with the **Admin Dashboard (`dashboard.php`)**
108 |
--------------------------------------------------------------------------------
/09_adminDashboardPageSetup.md:
--------------------------------------------------------------------------------
1 | ### Step-by-Step Documentation for Admin Dashboard (`admin/dashboard.php`)
2 |
3 | ---
4 |
5 | #### Purpose
6 | The **Admin Dashboard** serves as the central control panel for managing the e-commerce site. It provides navigation links to key admin functionalities like adding and managing products.
7 |
8 | ---
9 |
10 | #### 1. Session Authentication
11 | Ensure only authenticated admins can access the dashboard:
12 |
13 | ```php
14 |
21 | ```
22 |
23 | **How It Works**:
24 | - `session_start()` initializes the session.
25 | - The script checks if `admin_id` is set in the session. If not, it redirects to the login page.
26 |
27 | ---
28 |
29 | #### 2. HTML Structure of the Dashboard
30 | The dashboard includes navigation links for admin operations and a logout button:
31 |
32 | ```html
33 |
34 |
35 |
36 |
37 |
38 | Admin Dashboard
39 |
87 |
88 |
89 |
90 |
Admin Dashboard
91 |
96 |
97 |
100 |
101 |
102 | ```
103 |
104 | ---
105 |
106 | #### 3. Features
107 | - **Add Product**: Link to `add_product.php` for creating new product entries.
108 | - **Manage Products**: Link to `manage_products.php` for editing or deleting products.
109 | - **Logout**: Ends the admin session and redirects to the login page.
110 |
111 | ---
112 |
113 | #### 4. Testing the Dashboard
114 | 1. Log in as an admin.
115 | 2. Navigate to `http://localhost/ecommerce/admin/dashboard.php`.
116 | 3. Verify:
117 | - The session check prevents unauthorized access.
118 | - Links navigate to their respective pages.
119 | - The logout button works as expected.
120 |
121 | ---
122 |
123 | Next proceed with **Manage Products (`admin/manage_products.php`)**.
124 |
--------------------------------------------------------------------------------
/10_adminManageProductsPageSetup.md:
--------------------------------------------------------------------------------
1 | ### Step-by-Step Documentation for Admin Manage Products Page (`admin/manage_products.php`)
2 |
3 | ---
4 |
5 | #### Purpose
6 | The **Manage Products Page** allows administrators to view, edit, and delete existing products in the e-commerce database.
7 |
8 | ---
9 |
10 | #### 1. Session Authentication
11 | Ensure only logged-in admins can access the page:
12 |
13 | ```php
14 |
21 | ```
22 |
23 | ---
24 |
25 | #### 2. Fetch Products from the Database
26 | Fetch all products from the database to display in a table:
27 |
28 | ```php
29 | query("SELECT * FROM products");
32 | $products = $stmt->fetchAll(PDO::FETCH_ASSOC);
33 | ?>
34 | ```
35 |
36 | ---
37 |
38 | #### 3. HTML Structure
39 | Display the fetched products in a structured table:
40 |
41 | ```html
42 |
43 |
44 |
45 |
46 |
47 | Manage Products
48 |
96 |
97 |
98 |
99 |