<?php include "../../connect/db.php"; ?>

<?php
if (isset($_POST['cryptostats']) && isset($_POST['email'])) {
    $cryptostats = $_POST['cryptostats'];
    $email = $_POST['email'];

    // Prepare and bind
    $stmt = $con->prepare("UPDATE users SET crypto_status = ? WHERE email = ?");
    if ($stmt) {
        $stmt->bind_param('ss', $cryptostats, $email);

        // Execute the statement
        if ($stmt->execute()) {
            // Return success based on the value of cryptostats
            if ($cryptostats === "on") {
                echo "on";
            } else if ($cryptostats === "off") {
                echo "off";
            } else {
                echo "Invalid value";
            }
        } else {
            echo "Error executing query: " . $stmt->error;
        }
        $stmt->close();
    } else {
        echo "Error preparing statement: " . $con->error;
    }
} else {
    echo "Required parameters are missing";
}

$con->close();
?>
