<?php
include '../include/config.php';

echo "<h2>Testing Database Connection</h2>";

// Test connection
if ($conn) {
    echo "<p style='color:green'>✓ Database connected successfully</p>";
} else {
    echo "<p style='color:red'>✗ Database connection failed</p>";
}

// Test insert
echo "<h3>Test Insert:</h3>";
$test_username = "testuser_" . time();
$test_sql = "INSERT INTO users (username, email, password, role, full_name, status, approval_status, created_at) 
             VALUES ('$test_username', 'test@test.com', 'test123', 'staff', 'Test User', 'inactive', 'pending', NOW())";

if ($conn->query($test_sql)) {
    $last_id = $conn->insert_id;
    echo "<p style='color:green'>✓ Test insert successful! ID: $last_id</p>";
    
    // Clean up
    $conn->query("DELETE FROM users WHERE user_id = $last_id");
    echo "<p>✓ Test record deleted</p>";
} else {
    echo "<p style='color:red'>✗ Test insert failed: " . $conn->error . "</p>";
}
?>