<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$db = new SQLite3('./api/.db.db');

$res = $db->query("SELECT *
				  FROM users
				  WHERE id='1'");
$row=$res->fetchArray();

if(isset($_POST['submit'])){
$db->exec("UPDATE users SET	username='".$_POST['username']."',
							password='".$_POST['password']."'
						  WHERE
							id='1' ");
session_regenerate_id();
$_SESSION['loggedin'] = TRUE;
$_SESSION['name'] = $_POST['username'];
header("Location: main.php");
}


include ('includes/header.php');

?>

		<div class="col-md-4 mx-auto">
			<div class="card-body">
				<div class="card bg-dark text-white">
					<div class="card-header card-header-warning">
						<center>
							<h2><i class="icon icon-bullhorn"></i> Admin</h2>
						</center>
					</div>

					<div class="card-body">
						<div class="col-12">
							<h3>Edit Admin</h3>
						</div>
							<form method="post">
								<div class="form-group">
									<label class="form-label " for="username">Username</label>
										<input class="form-control" id="description" name="username" value="<?=$row['username'] ?>" type="text"/>
								</div>
								<div class="form-group">
									<label class="form-label " for="password">Password</label>
										<input class="form-control" id="description" name="password" value="<?=$row['password'] ?>" type="text"/>
								</div>
								<div class="form-group">
									<center>
										<button class="btn btn-info " name="submit" type="submit">
											<i class="icon icon-check"></i> Submit
										</button>
									</center>
								</div>
							</form>
					</div>
				</div>
			</div>
		</div>

<?php include ('includes/footer.php');?>
</body>
</html>
