<?php
include 'db/config.php';
if (isset($_POST['save'])) {
    $id = $_POST['id'];
    
    $username = $_POST['username'];
    $password = $_POST['password'];
    $level = $_POST['level'];

    mysqli_query($conn, "UPDATE user SET username='$username',password='$password',level='$level' WHERE id=$id");
    
    header('location: change.php');
}

$result = mysqli_query($conn,"SELECT * FROM user WHERE id='" . $_GET['id'] . "'");
$row= mysqli_fetch_array($result);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Update Record</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>

    <style type="text/css">
    * {
        margin: 0px;
        padding: 0px;
    }
    </style>

</head>
<body>
    <div class="login">
        <div class="account-login">
            <h1>Update Record</h1>
            <form action="view_change.php" method="POST" class="login-form">
                <input type="hidden" name="id" class="txtField" value="<?php echo $row['id']; ?>">

                

                <div class="form-group">
                    <input type="text" placeholder="Receiver Name" class="form-control" name="username" required="" value="<?php echo $row['username']; ?>">
                </div>

                <div class="form-group">
                    <input type="text" placeholder="Tracking Number" class="form-control" name="password" required="" value="<?php echo $row['password']; ?>">
                </div>

                <div class="form-group">
                    <input type="text" placeholder="Level" class="form-control" name="level" required="" value="<?php echo $row['level']; ?>">
                </div>
                <button type="submit" class="btnsave" name="save">Save Record</button>
            </form>
        </div>
    </div>
</body>
</html>

