# Email Display Troubleshooting Guide

## Issue
Email is not showing in the top bar for current user/supervisor.

## Possible Causes & Solutions

### 1. Check if Email Column Exists
Visit: `https://testkkcp.sheervantage.com/php/check_users_table.php`

This will:
- Show the Users table structure
- Check if Email column exists
- Display sample user data

**If Email column is missing:**
Run this SQL in your database:
```sql
ALTER TABLE Users ADD COLUMN Email VARCHAR(255) NULL AFTER Username;
```

### 2. Check Current Session Data
Visit: `https://testkkcp.sheervantage.com/php/debug_session.php`

This will:
- Show all current session variables
- Automatically update session with email if missing
- Display any errors

### 3. Re-login
If you were already logged in before the email feature was added:
1. Click "Logout" in the top bar
2. Login again with your username/email and password
3. Email should now appear in the top bar

### 4. Update Existing User Emails
If users don't have emails in the database, you need to add them:

```sql
-- Update admin email
UPDATE Users SET Email = 'admin@kkcpbd.com' WHERE Username = 'admin';

-- Update other users
UPDATE Users SET Email = 'user@example.com' WHERE Username = 'username';
```

## What Was Changed

### Files Modified:
1. **header.php** - Top bar now fetches and displays email
2. **auth/login.php** - Stores email in session during login
3. **check_users_table.php** - Diagnostic tool to check table structure
4. **debug_session.php** - Diagnostic tool to check session data

### How It Works:
1. During login, email is fetched from Users table and stored in `$_SESSION['email']`
2. Top bar reads email from session
3. If not in session, fetches from database and updates session
4. Displays email below username in smaller text
5. Shows "No email set" if email is empty/null

## Quick Fix Steps

1. Visit `check_users_table.php` to verify Email column exists
2. If missing, add the column using the SQL above
3. Update user emails in the database
4. Visit `debug_session.php` to update your current session
5. Or simply logout and login again

## After Fixing

Once email is working:
- You can delete `check_users_table.php`
- You can delete `debug_session.php`
- These are just diagnostic tools

## Support

If email still doesn't show after following these steps:
1. Check browser console for JavaScript errors
2. Check PHP error logs
3. Verify the Users table has the Email column
4. Verify your user record has an email value
