<?php
session_start();
$name = $_SESSION['nombre'];
$id = $_SESSION['id'];

$servername = "localhost";
$username = "itladevprubycom_enma";
$password = "53gNpj4t.xDc";
$database = "itladevprubycom_enma1";

// Crear conexión
$conexion = new mysqli($servername, $username, $password, $database);

// Verificar conexión
if ($conexion->connect_error) {
    die("Error de conexión: " . $conexion->connect_error);
}
if(!empty($_GET["id"])){
    $id = $_GET["id"];
}

$query = $conexion->prepare("SELECT * FROM Usuarios");
$query->execute();

$data = $query->get_result();

if ($_SERVER["REQUEST_METHOD"] === "POST") {
    if (isset($_POST["tipo"])) {
        $id = $_POST["tipo"];
        header("Location: editar.php?id=".$id);
        exit();
    }
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Editar Registro</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.18.1/dist/css/uikit.min.css" />
    <script src="https://cdn.jsdelivr.net/npm/uikit@3.18.1/dist/js/uikit.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/uikit@3.18.1/dist/js/uikit-icons.min.js"></script>
</head>
<body>
    <?php include "navbar.php";?>
    <div class="uk-card uk-card-body uk-flex uk-flex-center">
    <div class="uk-container">
        <form action="" method="post">
            <h3>¿Cuál usuario quiere editar?</h3>
            <div class="uk-margin">
                <div class="uk-form-controls">
                    <select class="uk-select uk-form-medium" name="tipo" id="form-stacked-select">
                        <?php foreach($data as $value) {?>
                            <option value="<?php echo $value['id']?>"><?php echo $value['nombre']?></option>
                        <?php }?>
                    </select>
                </div>
            </div>
            <div class="uk-margin uk-flex uk-flex-center">
                <button type="submit" class="uk-button uk-button-default">Submit</button>
            </div>
        </form>
    </div>
</div>
<div class="uk-container uk-flex uk-flex-center uk-margin-small-top">
    <a href="index.php" class="uk-button uk-button-default">Volver al inicio</a>
</div>


</body>
</html>