================================================================================
  FIX: Student Registration Table Missing
================================================================================

ERROR:
------
SQLSTATE[42S02]: Base table or view not found: 1146 
Table 'melane_multi_tenant_skoloi.student_applications' doesn't exist

WHERE:
------
https://test.melanegroup.com/Multi-Tanent/stmarks/register
When submitting student registration form

CAUSE:
------
Database table not created yet

================================================================================
THE FIX (2 MINUTES):
================================================================================

STEP 1: Open the SQL File
--------------------------
Location: C:\xampp\htdocs\Multi-Tanent\database\migrations\create_student_applications_table.sql
Status: OPEN in Windows Explorer now!

STEP 2: Copy SQL Content
-------------------------
1. Double-click the file to open in text editor
2. Select All (Ctrl+A)
3. Copy (Ctrl+C)

STEP 3: Run in phpMyAdmin
--------------------------
1. Login to cPanel
2. Open phpMyAdmin
3. Select database: melane_multi_tenant_skoloi
4. Click "SQL" tab
5. Paste the SQL code
6. Click "Go"

STEP 4: Verify Success
-----------------------
You should see:
  ✓ Table student_applications created
  ✓ Table student_application_subjects created
  ✓ 2 queries executed successfully

================================================================================
VERIFICATION:
================================================================================

Quick Test Query (Run in phpMyAdmin):
--------------------------------------
DESCRIBE student_applications;

Expected Result:
----------------
Shows table structure with 30+ columns including:
- id
- academy_reference
- first_name
- last_name
- email
- phone
- date_of_birth
- gender
- grade_id
- parent_name
- parent_email
- parent_phone
- application_status
- payment_status
- email_verification_token
- email_verified
- student_id
- username
- password_plain
- etc.

================================================================================
TEST AFTER FIX:
================================================================================

1. Visit: https://test.melanegroup.com/Multi-Tanent/stmarks/register

2. Fill out form:
   - Enter student details
   - Select grade
   - Choose subjects (minimum 3)
   - Enter parent info

3. Submit application

4. Expected Result:
   ✅ "Application submitted successfully!"
   ✅ "Verification email sent to [email]"
   ✅ Redirect to verification page

================================================================================
WHAT THIS TABLE DOES:
================================================================================

WORKFLOW:
---------
Step 1: Student fills registration form
Step 2: Data saved to student_applications table (status: submitted)
Step 3: Email verification sent (email_verification_token created)
Step 4: Student clicks email link (status: verified)
Step 5: Student makes payment (payment_status: paid)
Step 6: Admin approves OR auto-approve (status: approved)
Step 7: Account created in students table (student_id saved)
Step 8: Credentials emailed (username & password)
Step 9: Application completed (status: completed)

TABLES CREATED:
---------------
1. student_applications
   - Stores all application data
   - Tracks status through workflow
   - Records payment details
   - Stores generated credentials

2. student_application_subjects
   - Links applications to selected subjects
   - One row per subject per application
   - Used to calculate fees
   - Used to create enrollments after approval

================================================================================
CURRENT STATUS:
================================================================================

WORKING:
--------
✅ Clean URL: /stmarks/register
✅ School branding: "St Marks High Shool"
✅ Multi-step form
✅ Grade selection (Form 3, Grade 7)
✅ Subject loading
✅ Fee calculation
✅ Form validation
✅ Parent info collection

NOT WORKING (YET):
------------------
❌ Form submission (table missing)

AFTER FIX:
----------
✅ Everything will work!

================================================================================
FILE OPENED IN EXPLORER:
================================================================================

File: create_student_applications_table.sql
Location: C:\xampp\htdocs\Multi-Tanent\database\migrations\

Just copy the contents and run in phpMyAdmin!

================================================================================
TIME REQUIRED: 2 minutes
DIFFICULTY: Very Easy
IMPACT: Registration system fully functional!
================================================================================

