<?php
// FXH — DIRECT LICENSE UPDATE TEST

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

require_once __DIR__ . "/config.php";

$license = "152441998696";
$newMt5  = "876456";

echo "<pre>";

// 1) SHOW BEFORE
echo "=== BEFORE ===\n";
$sql_before = "SELECT id, license_key, mt5_account, active FROM fxh_licenses WHERE license_key = '$license'";
$res_before = $conn->query($sql_before);

if (!$res_before) {
    echo "BEFORE QUERY ERROR: " . $conn->error . "\n";
} else {
    while ($row = $res_before->fetch_assoc()) {
        echo "id={$row['id']} | license_key={$row['license_key']} | mt5_account={$row['mt5_account']} | active={$row['active']}\n";
    }
}

// 2) RUN UPDATE
$sql_update = "
    UPDATE fxh_licenses
    SET mt5_account = '$newMt5'
    WHERE license_key = '$license'
";

echo "\n=== UPDATE ===\n";
echo $sql_update . "\n\n";

$ok = $conn->query($sql_update);
if (!$ok) {
    echo "UPDATE ERROR: " . $conn->error . "\n";
} else {
    echo "UPDATE OK\n";
    echo "AFFECTED ROWS: " . $conn->affected_rows . "\n";
}

// 3) SHOW AFTER
echo "\n=== AFTER ===\n";
$res_after = $conn->query($sql_before);
if (!$res_after) {
    echo "AFTER QUERY ERROR: " . $conn->error . "\n";
} else {
    while ($row = $res_after->fetch_assoc()) {
        echo "id={$row['id']} | license_key={$row['license_key']} | mt5_account={$row['mt5_account']} | active={$row['active']}\n";
    }
}

echo "</pre>";
