<?php
include('../includes/config.php');
if (!$con) {
    die("Connection failed: " . mysqli_connect_error());
}

$search = "test";
echo "Searching for users with 'test' in name or username...\n";

// Check users table
$sql = "SELECT id, username, email, password, role FROM users WHERE username LIKE '%$search%' OR email LIKE '%$search%'";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    echo "Found " . mysqli_num_rows($result) . " user(s):\n";
    while ($row = mysqli_fetch_assoc($result)) {
        echo "ID: " . $row['id'] . "\n";
        echo "Username: " . $row['username'] . "\n";
        echo "Email: " . $row['email'] . "\n";
        echo "Role: " . $row['role'] . "\n";
        echo "Password Hash: " . $row['password'] . "\n";

        // Also check user_details for full name
        $uid = $row['id'];
        $sql2 = "SELECT name, contactno FROM user_details WHERE user_id='$uid'";
        $res2 = mysqli_query($con, $sql2);
        if ($row2 = mysqli_fetch_assoc($res2)) {
            echo "Name: " . $row2['name'] . "\n";
            echo "Contact: " . $row2['contactno'] . "\n";
        }
        echo "--------------------------------\n";
    }
} else {
    echo "No users found in 'users' table.\n";
}
?>