<?php
include('config.php');

// Test username
$test_hwid = "DIRECT_TEST_" . time();
$test_username = "vax123_direct";

echo "Testing direct database operations\n";
echo "HWID: $test_hwid\n";
echo "Username: $test_username\n\n";

// Insert record
$insert_query = "INSERT INTO logs (hwid, username, Passwords, last_updated) VALUES (?, ?, 5, NOW())";
$stmt = mysqli_prepare($condb, $insert_query);
mysqli_stmt_bind_param($stmt, "ss", $test_hwid, $test_username);
$result = mysqli_stmt_execute($stmt);

if (!$result) {
    echo "Error inserting: " . mysqli_error($condb) . "\n";
    exit;
}

$inserted_id = mysqli_insert_id($condb);
echo "Record inserted with ID: $inserted_id\n\n";

// Check what was saved
$check_query = "SELECT * FROM logs WHERE id_log = ?";
$stmt = mysqli_prepare($condb, $check_query);
mysqli_stmt_bind_param($stmt, "i", $inserted_id);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);

if ($row = mysqli_fetch_assoc($result)) {
    echo "Database record:\n";
    echo "HWID: " . $row['hwid'] . "\n";
    echo "Username: " . $row['username'] . "\n";
    
    if ($row['username'] === $test_username) {
        echo "SUCCESS: Username matches the test value\n";
    } else {
        echo "ERROR: Username doesn't match! Expected '$test_username', got '" . $row['username'] . "'\n";
    }
} else {
    echo "Error: Could not retrieve record\n";
}

// Clean up
$delete_query = "DELETE FROM logs WHERE id_log = ?";
$stmt = mysqli_prepare($condb, $delete_query);
mysqli_stmt_bind_param($stmt, "i", $inserted_id);
mysqli_stmt_execute($stmt);
echo "\nTest record deleted.\n";
?> 