The following files exists in this folder. Click to view.
skapa_bankkonto.php42 lines UTF-8 Unix (LF)
<?php
session_start();
require_once("database_connection.php");
#Kollar inputen efter skadliga tecken
$bannedchars = [' ', '>', ';', '='];
foreach($bannedchars as $char){
if(strpos($_POST['Bankkonto_namn'], $char) !== false){
header('location: hemsida.php?mess=Inga förbjudna tecken! (Mellanslag, <, >, ; och =)');
exit();
}
}
$accountName = trim($_POST['Bankkonto_namn']);
$userId = $_SESSION['userId'];
#Skapar bankkontot och sätter in i tabellen
$sql = "INSERT INTO account (accountId, accountName, userId) VALUES (NULL, :accountName, :userId);";
$stm = $pdo->prepare($sql);
$stm->execute(array('accountName' => $accountName, 'userId' => $userId));
#Skaffar accountId för kontot för att senare kunna sätta in 1000kr
$sql = "SELECT * FROM account WHERE userId = :userId AND accountName = :accountName;";
$stm = $pdo->prepare($sql);
$stm->execute(array('userId' => $userId, 'accountName' => $accountName));
$res = $stm->fetch(PDO::FETCH_ASSOC);
$accountId = $res['accountId'];
#Sätter in 1000kr på det nyskapta kontot
date_default_timezone_set('Europe/Stockholm');
$date = date('Y-m-d H:i:s');
$amount = 1000;
$sql = "INSERT INTO transaction (transactionId, amount, date, accountId) VALUES (NULL, :amount, :date, :accountId);";
$stm = $pdo->prepare($sql);
$stm->execute(array('amount' => $amount, 'date' => $date, 'accountId' => $accountId));
header('location: hemsida.php');
?>