Path : /home/vishqocm/pcib.in/
File Upload :
Current File : /home/vishqocm//pcib.in/check_payments_table.php

<?php
// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Include database connection
require_once 'includes/db_connect.php';

// Get payment table structure
$sql = "SHOW CREATE TABLE payments";
$result = $conn->query($sql);

if ($result && $result->num_rows > 0) {
    $row = $result->fetch_row();
    echo "<pre>";
    echo $row[1];
    echo "</pre>";
} else {
    echo "Error: " . $conn->error;
}

// Check for all tables
echo "<h2>All Tables</h2>";
$result = $conn->query("SHOW TABLES");

if ($result) {
    echo "<ul>";
    while ($row = $result->fetch_row()) {
        echo "<li>" . $row[0] . "</li>";
    }
    echo "</ul>";
} else {
    echo "Error: " . $conn->error;
}

// Check sample data from payments
echo "<h2>Sample Data from Payments Table</h2>";
$result = $conn->query("SELECT * FROM payments LIMIT 5");
if ($result) {
    if ($result->num_rows > 0) {
        echo "<table border='1'>";
        // Get field names
        $fields = $result->fetch_fields();
        echo "<tr>";
        foreach ($fields as $field) {
            echo "<th>" . $field->name . "</th>";
        }
        echo "</tr>";
        
        // Reset the result pointer
        $result->data_seek(0);
        
        // Get data rows
        while ($row = $result->fetch_assoc()) {
            echo "<tr>";
            foreach ($row as $value) {
                echo "<td>" . htmlspecialchars($value ?? 'NULL') . "</td>";
            }
            echo "</tr>";
        }
        echo "</table>";
    } else {
        echo "No records found in payments table.";
    }
} else {
    echo "Error querying payments table: " . $conn->error;
}

// Test the specific query that's failing
echo "<h2>Testing the Problematic Query</h2>";
try {
    $test_query = "SELECT p.id, p.payment_method FROM payments p 
                  INNER JOIN enrollment_applications ea ON p.enrollment_id = ea.id 
                  WHERE ea.user_id = 1 AND ea.course_id = 1 
                  ORDER BY p.payment_date DESC LIMIT 1";
    $result = $conn->query($test_query);
    echo "Query executed successfully!";
} catch (Exception $e) {
    echo "Query error: " . $e->getMessage();
}

// Check if enrollment_applications table exists
echo "<h2>Enrollment Applications Table Structure</h2>";
$result = $conn->query("DESCRIBE enrollment_applications");
if ($result) {
    echo "<table border='1'>";
    echo "<tr><th>Field</th><th>Type</th><th>Null</th><th>Key</th><th>Default</th><th>Extra</th></tr>";
    while ($row = $result->fetch_assoc()) {
        echo "<tr>";
        echo "<td>" . $row['Field'] . "</td>";
        echo "<td>" . $row['Type'] . "</td>";
        echo "<td>" . $row['Null'] . "</td>";
        echo "<td>" . $row['Key'] . "</td>";
        echo "<td>" . $row['Default'] . "</td>";
        echo "<td>" . $row['Extra'] . "</td>";
        echo "</tr>";
    }
    echo "</table>";
} else {
    echo "Error: " . $conn->error;
}
?>