????????????????????
??????????????????
ÿØÿà
 JFIF      ÿÛ C      


!"$"$ÿÛ C    
ÿÂ p 
" ÿÄ     
         ÿÄ             ÿÚ 
   ÕÔË®

(%	aA*‚XYD¡(J„¡E¢RE,P€XYae )(E¤²€B¤R¥	BQ¤¢ X«)X…€¤   @  

adadasdasdasasdasdas


.....................................................................................................................................????????????????????
??????????????????
ÿØÿà
 JFIF      ÿÛ C      


!"$"$ÿÛ C    
ÿÂ p 
" ÿÄ     
         ÿÄ             ÿÚ 
   ÕÔË®

(%	aA*‚XYD¡(J„¡E¢RE,P€XYae )(E¤²€B¤R¥	BQ¤¢ X«)X…€¤   @  

adadasdasdasasdasdas


.....................................................................................................................................<?php
// Turn off all error reporting to prevent mixed output
error_reporting(0);
ini_set('display_errors', 0);

// Start output buffering to catch any unwanted output
ob_start();

// Clean any previous output
ob_clean();

// Set JSON header
header('Content-Type: application/json');

// Include connection - but catch any errors
try {
    include 'connection.php';
    
    if (isset($_POST['admission_no']) && !empty($_POST['admission_no'])) {
        $admission_no = mysqli_real_escape_string($conn, $_POST['admission_no']);
        
        // Check if accounts table exists
        $table_check = "SHOW TABLES LIKE 'accounts'";
        $table_result = $conn->query($table_check);
        
        if ($table_result && $table_result->num_rows > 0) {
            // Table exists, check for admission data
            $sql = "SELECT admission_no, total_fees, due_amount, paid_amount, received_amount FROM accounts WHERE admission_no = '$admission_no'";
            $result = $conn->query($sql);
            
            if ($result && $result->num_rows > 0) {
                // Record found in accounts table
                $row = $result->fetch_assoc();
                $response = array(
                    'found' => true,
                    'data' => array(
                        'admission_no' => $row['admission_no'],
                        'total_fees' => $row['total_fees'],
                        'due_amount' => $row['due_amount'],
                        'paid_amount' => $row['paid_amount'],
                        'received_amount' => $row['received_amount']
                    )
                );
                
                // Clean output buffer and send JSON
                ob_clean();
                echo json_encode($response);
                exit;
            } else {
                // No record found in accounts table
                $response = array(
                    'found' => false,
                    'data' => null,
                    'message' => 'No record found in accounts table'
                );
                
                ob_clean();
                echo json_encode($response);
                exit;
            }
        } else {
            // Accounts table doesn't exist
            $response = array(
                'found' => false,
                'data' => null,
                'message' => 'Accounts table does not exist'
            );
            
            ob_clean();
            echo json_encode($response);
            exit;
        }
    } else {
        // No admission number provided
        $response = array(
            'found' => false,
            'data' => null,
            'message' => 'No admission number provided'
        );
        
        ob_clean();
        echo json_encode($response);
        exit;
    }
    
} catch (Exception $e) {
    // Handle any errors
    ob_clean();
    echo json_encode(array(
        'found' => false,
        'data' => null,
        'error' => 'Database error: ' . $e->getMessage()
    ));
    exit;
}

// Close connection if it exists
if (isset($conn)) {
    $conn->close();
}
?>