<?php
session_start();
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");
header('Content-Type: application/json; charset=utf-8');


if (isset($_POST['id'])) {
    include 'config.php';

    $id = $_POST['id'];
 
    $id = stripslashes($id);
    $id = mysqli_escape_string($con, $id);

    
      

    $sql = $con->query("SELECT * FROM scholarships WHERE id = '$id'") 
        or die("Error: " . mysqli_error($con));

    if ($sql->num_rows > 0) {
        $data = [];
        while ($rows = mysqli_fetch_assoc($sql)) {
            
            $data[] = $rows;
        }

        $suc = "Success";
        $status = true;
    } else {
        $data = [];
        $suc = "No record found";
        $status = false;
    }

    $con->close();


    $output = array('success' => $suc, 'status' => $status,  'data' => $data);
    echo json_encode($output); // Output JSON data
} else {
    echo json_encode(array('success' => "Failure", 'status' => false, 'message' => "Missing required fields"));
}
?>
