---
description: Settings page fixes and functional store settings implementation
---

# Settings System Implementation

## Problem Fixed
Settings page had errors:
- Used non-existent `admin` table
- Settings were not functional
- No database integration

## Solution Implemented

### 1. Fixed Authentication
- Updated to use `users` table instead of `admin` table
- Changed session from `$_SESSION['aid']` to `$_SESSION['id']`
- Added admin-security.php for proper authentication

### 2. Created Functional Settings System

**Files Created:**
- `/includes/settings.php` - Settings helper library
- `/__admin__/sql/site_settings.sql` - Database schema
- `/setup/setup-settings.php` - Web-based setup
- `/setup/create_site_settings.sql` - Manual SQL import

**Database Table:**
```sql
CREATE TABLE site_settings (
    id INT PRIMARY KEY AUTO_INCREMENT,
    setting_key VARCHAR(100) UNIQUE,
    setting_value TEXT,
    setting_type VARCHAR(20),
    updated_at TIMESTAMP,
    updated_by INT
);
```

**Helper Functions Available:**
```php
get_setting('key', 'default')  // Get setting value
update_setting('key', 'value') // Update setting
currency_symbol()              // Returns: ₵
currency_code()                // Returns: GHS
store_name()                   // Returns: Awesome Mall
format_currency($amount)       // Returns: ₵ 100.00
```

### 3. Settings Available
- Store Name
- Currency (Ghana Cedis - GHS ₵)
- Support Email
- Support Phone
- Tax Rate (%)
- Default Shipping Fee
- Timezone
- Meta tags
- Feature toggles

### 4. Admin Settings Page
**File:** `/__admin__/settings.php`

**Features:**
- Update admin profile (name, email)
- Change password
- Update store settings (saves to database)
- View system information

**Functional Sections:**
1. Profile Settings (working)
2. Password Change (working)
3. Store Settings (working - saves to DB)
4. System Information (read-only)

## Setup Instructions

**Option 1 - Web Setup (Recommended):**
```
http://localhost/awesome-mall/setup/setup-settings.php
```

**Option 2 - Manual SQL:**
1. Open phpMyAdmin
2. Select `shopping` database
3. Import: `/setup/create_site_settings.sql`

## Usage Example

```php
// In any PHP file
include_once('includes/settings.php');

echo store_name();              // Awesome Mall
echo currency_symbol();         // ₵
echo format_currency(100);      // ₵ 100.00
echo get_setting('support_email'); 
```

## Status: ✅ COMPLETE
All store settings now save to database and apply site-wide!
