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

// Retrieve user ID and points to update from GET request (sanitize them)
$id = isset($_GET['id']) ? intval($_GET['id']) : 0; // Sanitize input to avoid SQL injection
$pointsToUpdate = isset($_GET['pointsToUpdate']) ? intval($_GET['pointsToUpdate']) : 0; // Sanitize input

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

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

// Retrieve current points of the user
$sql = "SELECT point FROM User_Details WHERE id=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows > 0) {
    $row = $result->fetch_assoc();
    $currentPoints = $row["point"];

    // Update points
    $updatedPoints = $currentPoints + $pointsToUpdate;

    $updateSql = "UPDATE User_Details SET point=? WHERE id=?";
    $updateStmt = $conn->prepare($updateSql);
    $updateStmt->bind_param("ii", $updatedPoints, $id);
    if ($updateStmt->execute()) {
        echo "Points updated successfully";
    } else {
        echo "Error updating points: " . $conn->error;
    }
} else {
    echo "User not found";
}

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