View sourcecode

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

account.php

71 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
<?php
#Inloggning om användaren är inloggad
session_start();
if (!isset(
$_SESSION["userID"])) {
    
header("location: index.php");
    exit();
}

#Utloggning
if (isset($_GET["logout"])) {
    
session_unset();
    
session_destroy();
    
header("location: index.php");
    exit();
}

#Hämtar kontoinformation från användaren
require_once "functions/database.php";
$userID $_SESSION["userID"];
$user $db->query("SELECT * FROM accountDataView WHERE userID = :userID", array("userID"=>$_SESSION["userID"]));

#Hantera insättning
if (isset($_POST["amount"])) {
    if (
$_POST["amount"] > 0) {
        
$db->query("INSERT INTO `transaction`(`userID`, `value`) VALUES (:userID, :value)", array("userID"=>$userID"value"=>$_POST["amount"]));
        
$user["balance"] += $_POST["amount"];
        
//$user->rereadValues();
    
}
}

#Hantera uttagning
if (isset($_POST["amountout"])) {
    if (
$_POST["amountout"] <= $user["balance"]) {
        if(
$_POST["amountout"] > 0){
            
$db->query("INSERT INTO `transaction`(`userID`, `value`) VALUES (:userID, :value)", array("userID"=>$userID"value"=>-$_POST["amountout"]));
            
$user["balance"] -= $_POST["amountout"];
            
//$user->rereadValues();
        
}
    }
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Ditt konto</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <h2>Välkommen <?php echo $user["username"]; ?></h2>
    <p>Du har <?php
    
echo ($user["balance"]);
    
?>kr</p><br><br>
    <form action="" method="post" enctype="multipart/form-data" autocomplete="off">
        <h2>Gör insättning</h2>
        <label>Mängd</label>
        <input type="number" name="amount">
        <button type="submit" name="submit">Gör insättning</button>
    </form>
    <form action="" method="post" enctype="multipart/form-data" autocomplete="off">
        <h2>Tag ut pengar</h2>
        <label>Mängd</label>
        <input type="number" name="amountout">
        <button type="submit" name="submit">Tag ut</button>
    </form>
    <a href="?logout">Logga ut</a>
</body>