Path : /home/vishqocm/pcib.in/debug/
File Upload :
Current File : /home/vishqocm/pcib.in/debug/README.md

# Debug and Maintenance Tools

This directory contains tools for database maintenance and troubleshooting common issues.

## Security Warning

**IMPORTANT:** This directory should NOT be publicly accessible on production servers. Either:
1. Delete this directory before deploying to production
2. Protect it with proper authentication
3. Move it outside the public web root

## Available Tools

### Database Column Management

- **Update Users Table**: Adds all missing columns to the users table (profile_image, designation, expertise, bio, social_links)
- **Add Profile Image Column**: Quick fix to add only the profile_image column to the users table

### Database Table Creation

- **Create Theme Settings Table**: Creates the theme_settings table and populates it with default values
- **Fix Enrollments & Payments Tables**: Fixes the enrollments and payments tables by adding or renaming student_id column to user_id
- **Fix Enrollments Date Column**: Adds the missing enrollment_date column to the enrollments table
- **Fix Payments Date Column**: Adds the missing payment_date column to the payments table

### Code and Connection Fixes

- **Fix Database Connection**: Ensures proper database connection inclusion in header files

### Common Issues and Solutions

#### "Unknown column 'profile_image' in 'field list'"

This error occurs when the database is missing the profile_image column in the users table. To fix:

1. Visit `http://yoursite.com/debug/` 
2. Click "Run Tool" next to "Add Profile Image Column"
3. Or navigate directly to `http://yoursite.com/admin/add_profile_image_column.php`

#### "Table 'popularcomputer.theme_settings' doesn't exist"

This error occurs when the theme_settings table is missing from the database. To fix:

1. Visit `http://yoursite.com/debug/`
2. Click "Run Tool" next to "Create Theme Settings Table"
3. Or navigate directly to `http://yoursite.com/debug/database/create_theme_settings_table.php`

#### "Unknown column 'e.student_id' in 'on clause'"

This error occurs when the enrollments table is using student_id but the code is expecting user_id. To fix:

1. Visit `http://yoursite.com/debug/`
2. Click "Run Tool" next to "Fix Enrollments & Payments Tables"
3. Or navigate directly to `http://yoursite.com/debug/database/fix_enrollments_table.php`

#### "Unknown column 'e.enrollment_date' in 'order clause'"

This error occurs when the enrollments table is missing the enrollment_date column. To fix:

1. Visit `http://yoursite.com/debug/`
2. Click "Run Tool" next to "Fix Enrollments Date Column"
3. Or navigate directly to `http://yoursite.com/debug/database/fix_enrollments_date.php`

#### "Unknown column 'p.payment_date' in 'order clause'"

This error occurs when the payments table is missing the payment_date column. To fix:

1. Visit `http://yoursite.com/debug/`
2. Click "Run Tool" next to "Fix Payments Date Column"
3. Or navigate directly to `http://yoursite.com/debug/database/fix_payments_date.php`

#### "Warning: Undefined variable $conn"

This error occurs when a file (typically header.php) is trying to use the database connection variable ($conn) without it being defined. To fix:

1. Visit `http://yoursite.com/debug/`
2. Click "Run Tool" next to "Fix Database Connection"
3. Or navigate directly to `http://yoursite.com/debug/database/fix_conn_variable.php`

#### How to Move This Directory to Production

When moving to a production server:

1. Make a backup of your database
2. Upload the `/debug` directory to your production server
3. Run the necessary tools to update your database structure
4. Remove the `/debug` directory or secure it with proper authentication

## Usage in Development

During development, you can access these tools at:
- Debug dashboard: `http://localhost/debug/`
- Database tools: `http://localhost/debug/database/`

## Live Server Installation

When setting up on a live server, follow these steps:

1. Upload all website files except the `/debug` directory
2. Create a complete database backup
3. Upload the `/debug` directory (separately) 
4. Run the required tools to ensure proper database structure
5. Remove the `/debug` directory when finished

## Database Structure Documentation

The tools in this directory help maintain the following database structures:

### Users Table Columns
- `profile_image`: VARCHAR(255) - Path to user's profile image
- `designation`: VARCHAR(255) - Professional title or role
- `expertise`: TEXT - Areas of expertise (especially for instructors)
- `bio`: TEXT - Biographical information
- `social_links`: TEXT - JSON or serialized array of social media links

### Theme Settings Table
- `id`: INT AUTO_INCREMENT PRIMARY KEY
- `setting_key`: VARCHAR(100) NOT NULL UNIQUE - Name of the setting
- `setting_value`: TEXT NOT NULL - Value of the setting
- `created_at`: TIMESTAMP - When the setting was created
- `updated_at`: TIMESTAMP - When the setting was last updated

Default theme settings include:
- theme_name
- header_bg_color
- footer_bg_color
- text_color
- link_color
- button_style
- font_family
- custom_css

### Enrollments Table
- Should use `user_id` instead of `student_id` to reference users
- Requires `enrollment_date` column (TIMESTAMP) for storing when a user enrolled
- The fix_enrollments_table.php tool handles renaming or adding the user_id column
- The fix_enrollments_date.php tool adds the missing enrollment_date column

### Payments Table
- Should use `user_id` instead of `student_id` to reference users
- Requires `payment_date` column (TIMESTAMP) for storing when a payment was made
- The fix_enrollments_table.php tool handles renaming or adding the user_id column
- The fix_payments_date.php tool adds the missing payment_date column

## File Structure Fixes

### Header Files
The fix_conn_variable.php tool ensures that:
- Database configuration files are properly included at the top of header files
- Proper checks are added to ensure the $conn variable is available
- These fixes prevent "Undefined variable $conn" errors

## Security Recommendations

To protect your website:
- Keep these tools inaccessible to the public
- Use strong passwords for database and admin accounts
- Regularly update your website components
- Maintain regular backups
- Implement proper input validation and sanitization throughout the codebase