View sourcecode

The following files exists in this folder. Click to view.

hemsida.php

84 lines UTF-8 Unix (LF)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?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>