<?php
include("../includes/auth.php");
include("../config/db.php");

$id = $_GET['id'];

$data = $conn->query("SELECT * FROM users WHERE id=$id")->fetch_assoc();

if (isset($_POST['update'])) {
    $name = $_POST['name'];
    $mobile = $_POST['mobile'];

    $conn->query("UPDATE users SET name='$name', mobile='$mobile' WHERE id=$id");

    header("Location: index.php");
}
?>

<?php include("../includes/header.php"); ?>
<?php include("../includes/sidebar.php"); ?>

<h3>Edit Sub Admin</h3>

<form method="POST">
    <input type="text" name="name" value="<?= $data['name'] ?>" class="form-control mb-2">
    <input type="text" name="mobile" value="<?= $data['mobile'] ?>" class="form-control mb-2">
    <button name="update" class="btn btn-primary">Update</button>
</form>

<?php include("../includes/footer.php"); ?>