View sourcecode

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

account.php

59 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
<?php
session_start
();
if (!isset(
$_SESSION["user"])) {
    
header("location: login.php");
    exit();
}

if (isset(
$_GET["logout"])) {
    unset(
$_SESSION["user"]);
    
header("location: login.php");
    exit();
}
require(
"userdata.php");
$userdata = new UserData($_SESSION["user"]);
if (isset(
$_POST["amount"])) {
    if (
$_POST["amount"] > 0) {
        
array_push($userdata->user["balance"], intval($_POST["amount"]));
        
$userdata->saveUserData();
    }
}
if (isset(
$_POST["amountout"])) {
    if (
$_POST["amountout"] <= ($userdata->getBalance()) + 1000) {
        if(
$_POST["amountout"] > 0){
            
array_push($userdata->user["balance"], intval(($_POST["amountout"]) * -1));
            
$userdata->saveUserData();
        }
    }
}
?>

<!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 $_SESSION["user"]; ?></h2>
    <p>Du har <?php
    
echo ($userdata->getBalance() + 1000);
    
?>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>