View sourcecode

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

skapa_bankkonto.php

42 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
<?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');

?>