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

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

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

// Get 'mobile' from POST request
$mobile = $_POST['mobile'];

// Prepare the SQL statement to update Device_Active_Check to 0
$sql = "UPDATE User_Details SET Device_Active_Check = 0 WHERE mobile = ?";

// Prepare the statement
$stmt = $conn->prepare($sql);
if ($stmt) {
    // Bind parameters
    $stmt->bind_param("s", $mobile);

    // Execute the statement
    if ($stmt->execute()) {
        // Check if any row was affected
        if ($stmt->affected_rows > 0) {
            echo json_encode(["status" => "success", "message" => "Device_Active_Check updated successfully."]);
        } else {
            echo json_encode(["status" => "error", "message" => "No matching mobile number found."]);
        }
    } else {
        echo json_encode(["status" => "error", "message" => "Failed to update Device_Active_Check."]);
    }

    // Close the statement
    $stmt->close();
} else {
    echo json_encode(["status" => "error", "message" => "Database query preparation failed."]);
}

// Close the database connection
$conn->close();
?>
