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

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

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

if (isset($_POST['mobile']) && isset($_POST['point'])) {
    $mobile = $_POST['mobile'];
    $point = (int)$_POST['point'];

    // Prepare SQL query
    $sql = "UPDATE User_Details SET point = ? WHERE mobile = ?";
    $stmt = $conn->prepare($sql);
    
    if ($stmt === false) {
        echo json_encode(["status" => "error", "message" => "Failed to prepare SQL statement"]);
        exit();
    }
    
    $stmt->bind_param("is", $point, $mobile);

    // Execute the query
    if ($stmt->execute()) {
        // Verify if any rows were affected
        if ($stmt->affected_rows > 0) {
            echo json_encode(["status" => "success", "message" => "Details updated successfully"]);
        } else {
            echo json_encode(["status" => "error", "message" => "No changes made or user not found"]);
        }
    } else {
        echo json_encode(["status" => "error", "message" => "Failed to update details"]);
    }

    $stmt->close();
} else {
    echo json_encode(["status" => "error", "message" => "Missing required fields"]);
}

$conn->close();
?>
