# Certificate Verification Testing Guide

Complete step-by-step testing of the certificate verification system for EA-DEMO-2026-0001.

## Sample Certificate Data

| Field | Value |
|-------|-------|
| **Certificate ID** | EA-DEMO-2026-0001 |
| **Name** | Aafrah Hajira |
| **Email** | (blank) |
| **Education** | Fourth Semester, B.Tech in Electrical & Electronics Engineering |
| **Institution** | National Institute of Technology Karnataka (NITK), Surathkal – 575025 |
| **Role** | Summer Internship |
| **Company** | ExpertAims Consultancy LLP |
| **Location** | Kuwait Office |
| **Start Date** | 2026-06-20 |
| **End Date** | 2026-07-20 |
| **Issued Date** | 2026-07-20 |
| **Description** | Sincere, hardworking and inquisitive, demonstrated strong technical aptitude and professionalism. |
| **Status** | published |

## Setup Steps

### Step 1: Import Database Tables

In **cPanel → phpMyAdmin**:

1. Go to your database: `expertin_eac`
2. Click **Import**
3. Choose file: `database/upgrade-certificates.sql`
4. Click **Go**

**Expected Result:** ✓ Table created with sample data

### Step 2: Verify Table Created

Run this SQL in phpMyAdmin (SQL tab):

```sql
SELECT * FROM certificates WHERE certificate_id = 'EA-DEMO-2026-0001';
```

**Expected Result:** One row with Aafrah Hajira's certificate

### Step 3: Upload Files to cPanel

Upload these files to your cPanel public_html folder:

- `index.php` ← Updated with /verify route
- `app/helpers.php` ← Certificate functions
- `database/upgrade-certificates.sql` ← Keep for reference

### Step 4: Test the Verification Endpoint

#### Test 1: JSON API
```bash
curl "https://www.expertaims.com/verify?id=EA-DEMO-2026-0001"
```

**Expected Response:**
```json
{
  "ok": true,
  "certificate": {
    "id": "EA-DEMO-2026-0001",
    "name": "Aafrah Hajira",
    "role": "Summer Internship",
    "company": "ExpertAims Consultancy LLP",
    "location": "Kuwait Office",
    "start_date": "2026-06-20",
    "end_date": "2026-07-20",
    "issued_date": "2026-07-20",
    "education": "Fourth Semester, B.Tech in Electrical & Electronics Engineering",
    "institution": "National Institute of Technology Karnataka (NITK), Surathkal – 575025",
    "description": "Sincere, hardworking and inquisitive, demonstrated strong technical aptitude and professionalism."
  }
}
```

#### Test 2: HTML Page Form
Navigate to:
```
https://www.expertaims.com/verify
```

**Expected Result:**
- Beautiful form with certificate ID input
- FAQ section visible
- No errors

#### Test 3: Auto-Verify Link
Navigate to:
```
https://www.expertaims.com/verify?id=EA-DEMO-2026-0001
```

**Expected Result:**
- Form pre-filled with "EA-DEMO-2026-0001"
- Certificate details displayed immediately:
  - ✓ Certificate Verified
  - Name: Aafrah Hajira
  - Role: Summer Internship
  - Company: ExpertAims Consultancy LLP
  - Location: Kuwait Office
  - Duration: Jun 20, 2026 to Jul 20, 2026
  - Education: Fourth Semester, B.Tech in Electrical & Electronics Engineering
  - Institution: National Institute of Technology Karnataka (NITK), Surathkal – 575025
  - Certificate ID: EA-DEMO-2026-0001
  - Issued Date: Jul 20, 2026

#### Test 4: Invalid Certificate ID
```
https://www.expertaims.com/verify?id=INVALID-ID
```

**Expected Result:**
- ✗ Certificate not found
- Error message displayed
- "No certificate found for ID: INVALID-ID"

#### Test 5: Manual Form Entry
1. Visit `https://www.expertaims.com/verify`
2. Type "EA-DEMO-2026-0001" in the input
3. Click "Verify Certificate" button

**Expected Result:**
- Spinner shows briefly
- Certificate details appear
- No console errors

## Local Testing

### Option 1: Docker/Local PHP Server

```bash
cd /path/to/eac-cms
php -S localhost:8000
```

Then visit:
```
http://localhost:8000/verify?id=EA-DEMO-2026-0001
```

### Option 2: cPanel Web Terminal

1. Go to cPanel
2. Open Terminal/SSH
3. Run SQL import:
```bash
mysql -u expertin_eac -p expertin_eac < database/upgrade-certificates.sql
```

4. Verify data:
```bash
mysql -u expertin_eac -p -e "SELECT certificate_id, internee_name FROM certificates;" expertin_eac
```

**Expected Output:**
```
certificate_id      internee_name
EA-DEMO-2026-0001     Aafrah Hajira
```

## Verification Checklist

- [ ] Database table created
- [ ] Sample certificate imported (EA-DEMO-2026-0001)
- [ ] `index.php` uploaded (updated)
- [ ] `app/helpers.php` uploaded (updated)
- [ ] `/verify` page loads (empty form)
- [ ] `/verify?id=EA-DEMO-2026-0001` auto-verifies
- [ ] JSON API returns correct data
- [ ] Invalid IDs show error
- [ ] Mobile view works (responsive)
- [ ] Form submission works
- [ ] No PHP errors in logs

## Code Changes Made

### index.php
- Added `/verify` route handler (lines ~212-320)
- Supports both HTML and JSON responses
- Auto-verification from URL parameters

### app/helpers.php
- Added `find_certificate($cert_id)` function
- Added `all_certificates()` function
- Database queries use PDO prepared statements

### database/upgrade-certificates.sql
- Creates `certificates` table
- Inserts sample certificate (EA-DEMO-2026-0001)

## Database Schema

```sql
CREATE TABLE certificates (
  id INT AUTO_INCREMENT PRIMARY KEY,
  certificate_id VARCHAR(50) NOT NULL UNIQUE,
  internee_name VARCHAR(160) NOT NULL,
  email VARCHAR(190) DEFAULT NULL,
  education VARCHAR(255) DEFAULT NULL,
  institution VARCHAR(255) DEFAULT NULL,
  role VARCHAR(160) NOT NULL,
  company VARCHAR(255) NOT NULL,
  location VARCHAR(160) DEFAULT NULL,
  start_date DATE NOT NULL,
  end_date DATE NOT NULL,
  issued_date DATE NOT NULL,
  description TEXT DEFAULT NULL,
  status ENUM('published','draft') NOT NULL DEFAULT 'published',
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  KEY idx_cert_id (certificate_id),
  KEY idx_status (status)
);
```

## Troubleshooting

### "Table not found" error

**Issue:** Database table doesn't exist

**Fix:**
1. Import `database/upgrade-certificates.sql` in phpMyAdmin
2. Verify: `SELECT * FROM certificates;`

### "Certificate not found" when ID is correct

**Issue:** Certificate status is not "published"

**Fix:** Check in MySQL:
```sql
SELECT certificate_id, status FROM certificates WHERE certificate_id = 'EA-DEMO-2026-0001';
```

Should show: `EA-DEMO-2026-0001 | published`

### JSON API returns 404

**Issue:** Route not working or files not uploaded

**Fix:**
1. Verify `index.php` is updated (contains `/verify` route)
2. Check file was uploaded to cPanel
3. Check phpMyAdmin for certificate data
4. Check PHP error logs

### Form doesn't appear

**Issue:** CSS/JS not loading

**Fix:**
1. Check browser console (F12)
2. Verify `/assets/` folder exists
3. Check for 404 errors in Network tab

## Adding More Certificates

After testing with EA-DEMO-2026-0001, add more via SQL:

```sql
INSERT INTO certificates (
  certificate_id, internee_name, email, education, institution,
  role, company, location, start_date, end_date, issued_date,
  description, status
) VALUES (
  'EA-IN-2026-0721',
  'Jane Doe',
  'jane@example.com',
  'B.Tech in Computer Science',
  'NIT Karnataka',
  'Summer Internship',
  'ExpertAims Consultancy LLP',
  'Kuwait Office',
  '2026-06-20',
  '2026-07-20',
  '2026-07-20',
  'Excellent work',
  'published'
);
```

Then verify:
```
https://www.expertaims.com/verify?id=EA-IN-2026-0721
```

## Support

If verification fails:
1. Check MySQL logs: `tail -f /var/log/mysql/error.log`
2. Check PHP error log in cPanel
3. Verify file uploads: check cPanel File Manager
4. Test database connection: verify credentials in `.env`

---

**Certificate ID to Test:** EA-DEMO-2026-0001
**Status:** Ready for deployment ✓
