<?php
$servername = "localhost";
$username = "venmobdc_OnlineClassuser";
$password = "EuN&(VkTztyS";
$dbname = "venmobdc_OnlineClass";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$userId = $_POST['userId'];
$requiredPoints = $_POST['requiredPoints'];

$sql = "SELECT point FROM User_Details WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $userId);
$stmt->execute();
$stmt->bind_result($userPoints);
$stmt->fetch();

$response = array();
if ($userPoints >= $requiredPoints) {
    $response['status'] = 'success';
    $response['message'] = 'User has enough points.';
} else {
    $response['status'] = 'failure';
    $response['message'] = 'User does not have enough points.';
}

echo json_encode($response);

$stmt->close();
$conn->close();
?>
