The following files exists in this folder. Click to view.
admin.php79 lines UTF-8 Unix (LF) 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
<?php
# Kollar om vi är inloggade
require_once('check_login.php');
require_once('database_connection.php');
# shorthand if som tar hand om meddelandet
$mess = isset($_GET['mess']) ? "<p class='has-text-danger'>".$_GET['mess']."</p>" : "";
# Gör anropet till databasen
$sql = "SELECT * FROM user ORDER BY userId";
$stm = $pdo->prepare($sql);
$stm->execute();
# fetchAll() eftersom vi kan få flera poster
$res = $stm->fetchAll(PDO::FETCH_ASSOC);
# skapar hela tabellen som byggs upp
$table = "\n<table class='table is-striped is-hoverable is-fullwidth'>";
$table .= "\n <thead>\n <tr>\n <th>userId</th>\n <th>username</th>\n <th>password</th>\n <th>händelse</th>\n </tr>\n </thead>\n <tbody>";
# loopa igenom resultatset
foreach ($res as $row) {
$table .= "\n <tr>";
$table .= "\n <td>".$row['userId']."</td>";
$table .= "\n <td>".$row['username']."</td>";
$table .= "\n <td>".$row['password']."</td>";
$table .= "\n <td>
<a href='deleteUser.php?userId=".$row['userId']."'>ta bort</a> |
<a href='editUser.php?userId=".$row['userId']."'>ändra</a>
</td>";
$table .= "\n </tr>";
}
$table .= "\n </tbody>\n</table>";
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Inloggningsapplikation</title>
<!-- Bulma -->
<link rel="stylesheet" href="bulma.css">
</head>
<body>
<section class="section">
<div class="container">
<div class="columns is-centered">
<div class="column is-6">
<h1 class="title">Admin</h1>
<?php echo $mess; ?>
<p>Du är inloggad som <strong><?php echo $_SESSION['username']; ?></strong></p>
<p>
<a class="button is-small is-light" href="logout.php">Logga ut</a>
</p>
<h2 class="subtitle">Användare</h2>
<p>
<a class="button is-link is-small" href="addUser.php">
Lägg till ny användare
</a>
</p>
<?php echo $table; ?>
</div>
</div>
</div>
</section>
</body>
</html>