The following files exists in this folder. Click to view.
account.php71 lines UTF-8 Unix (LF) 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
<?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>