The following files exists in this folder. Click to view.
hemsida.php84 lines UTF-8 Unix (LF) 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
<?php
session_start();
if(!isset($_SESSION['inloggad'])){require_once('check_login.php');}
require_once('database_connection.php');
$mess = isset($_GET['mess']) ? "<p class='has-text-danger m-3'>".$_GET['mess']."</p>" : "";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="bulma.css">
<title>Hemsida</title>
</head>
<body>
<header class="title navbar has-shadow is-justify-content-center has-background-primary">Bankapplikation</header>
<div class="m-3">
<?php
#Om cookies är sparade, skriver ut användarnamnet för kontot och även sparar userId i en variabel för senare användning
if(isset($_COOKIE['Användarnamn'])){
$userId = $_COOKIE['userId'];
echo "Du är inloggad som: " . $_COOKIE['Användarnamn'];
} else{
$userId = $_SESSION['userId'];
echo "Du är inloggad som: " . $_SESSION['Användarnamn'];
}
?>
<form action="logout.php" method="post">
<input class="mt-2" type="submit" name="Logout" value="Logga ut"></input>
</form>
<?php echo $mess ?>
<form class="mt-2" action="skapa_bankkonto.php" method="post">
<p>Konto namn</p>
<input type="text" name="Bankkonto_namn" required placeholder autocomplete="off">
<br>
<input class="mt-2" type="submit" name="Skapa_bankkonto" value="Skapa konto"></input>
</form>
<?php
#Tar fram information om användarens konto
$sql = "SELECT * FROM account WHERE userId = :userId;";
$stm = $pdo->prepare($sql);
$stm->execute(array('userId' => $userId));
$res = $stm->fetchAll(PDO::FETCH_ASSOC);
$totalsaldo = 0;
#Bygger upp tabellen som visar informationen till användaren
$table = "<table class='table'>";
$table .= "<thead><tr><th>Konto</th><th>Saldo</th></tr></thead><tbody>";
foreach($res as $row){
$sql = "SELECT * FROM transaction WHERE accountId = :accountId";
$stm = $pdo->prepare($sql);
$stm->execute(array('accountId' => $row['accountId']));
$res1 = $stm->fetchAll(PDO::FETCH_ASSOC);
$saldo = 0;
foreach($res1 as $row1){
$saldo += $row1['amount'];
$totalsaldo += $row1['amount'];
}
$table .= "<tr>";
$table .= "<td>".$row['accountName']."</td>";
$table .= "<td>" .$saldo."kr</td>";
$table .= "<td><a href='transaktionsida.php?accountId=".$row['accountId']."'>Välj</a></td>";
$table .= "</tr>";
}
$table .= "<tr>";
$table .= "<td>Total Saldo:</td>";
$table .= "<td>".$totalsaldo."kr</td>";
$table .= "</tr>";
$table .= "</tbody></table>";
echo $table;
?>
</div>
</body>
</html>