-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.php
68 lines (64 loc) · 2.34 KB
/
function.php
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
<?php
function setBalance($amount,$process,$accountNo)
{
$con = new mysqli('localhost','root','','mybank');
$array = $con->query("select * from userAccounts where accountNo='$accountNo'");
$row = $array->fetch_assoc();
if ($process == 'credit')
{
$balance = $row['balance'] + $amount;
return $con->query("update userAccounts set balance = '$balance' where accountNo = '$accountNo'");
}else
{
$balance = $row['balance'] - $amount;
return $con->query("update userAccounts set balance = '$balance' where accountNo = '$accountNo'");
}
}
function setOtherBalance($amount,$process,$accountNo)
{
$con = new mysqli('localhost','root','','mybank');
$array = $con->query("select * from otheraccounts where accountNo='$accountNo'");
$row = $array->fetch_assoc();
if ($process == 'credit')
{
$balance = $row['balance'] + $amount;
return $con->query("update otheraccounts set balance = '$balance' where accountNo = '$accountNo'");
}else
{
$balance = $row['balance'] - $amount;
return $con->query("update otheraccounts set balance = '$balance' where accountNo = '$accountNo'");
}
}
function makeTransaction($action,$amount,$other)
{
$con = new mysqli('localhost','root','','mybank');
if ($action == 'transfer')
{
return $con->query("insert into transaction (action,debit,other,userId) values ('transfer','$amount','$other','$_SESSION[userId]')");
}
if ($action == 'withdraw')
{
return $con->query("insert into transaction (action,debit,other,userId) values ('withdraw','$amount','$other','$_SESSION[userId]')");
}
if ($action == 'deposit')
{
return $con->query("insert into transaction (action,credit,other,userId) values ('deposit','$amount','$other','$_SESSION[userId]')");
}
}
function makeTransactionCashier($action,$amount,$other,$userId)
{
$con = new mysqli('localhost','root','','mybank');
if ($action == 'transfer')
{
return $con->query("insert into transaction (action,debit,other,userId) values ('transfer','$amount','$other','$userId')");
}
if ($action == 'withdraw')
{
return $con->query("insert into transaction (action,debit,other,userId) values ('withdraw','$amount','$other','$userId')");
}
if ($action == 'deposit')
{
return $con->query("insert into transaction (action,credit,other,userId) values ('deposit','$amount','$other','$userId')");
}
}
?>