-
Notifications
You must be signed in to change notification settings - Fork 13
/
atm_simulator_action.php
140 lines (98 loc) · 3.18 KB
/
atm_simulator_action.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
include "validate_customer.php";
include "header.php";
include "customer_navbar.php";
include "customer_sidebar.php";
include "session_timeout.php";
$id = $_SESSION['loggedIn_cust_id'];
$amt = mysqli_real_escape_string($conn, $_POST["amt"]);
$type = mysqli_real_escape_string($conn, $_POST["type"]);
$pin = mysqli_real_escape_string($conn, $_POST["pin"]);
$sql0 = "SELECT balance FROM passbook".$id." ORDER BY trans_id DESC LIMIT 1";
$result = $conn->query($sql0);
$row = $result->fetch_assoc();
$balance = $row["balance"];
/* Set appropriate error number if errors are encountered.
Key (for err_no) :
-1 = Connection Error.
0 = Successful Transaction.
1 = Insufficient Funds.
2 = Wrong PIN entered. */
$err_no = -1;
$sql_pin = "SELECT * FROM customer WHERE cust_id=".$id." AND pin='".$pin."'";
$result_pin = $conn->query($sql_pin);
if (($result_pin->num_rows) > 0)
{
// For Credit transactions
if ($type == "credit") {
$final_balance = $balance + $amt;
$sql1 = "INSERT INTO passbook".$id." VALUES(
NULL,
NOW(),
'Cash Deposit',
'0',
'$amt',
'$final_balance'
)";
if (($conn->query($sql1) === TRUE)) {
$err_no = 0;
}
}
// For Debit transactions
if ($type == "debit") {
$final_balance = $balance - $amt;
if ($final_balance >= 0) {
$sql1 = "INSERT INTO passbook".$id." VALUES(
NULL,
NOW(),
'Cash to Self',
'$amt',
'0',
'$final_balance'
)";
if (($conn->query($sql1) === TRUE)) {
$err_no = 0;
}
}
else {
$err_no = 1;
}
}
}
else {
$err_no = 2;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="action_style.css">
</head>
<body>
<div class="flex-container">
<div class="flex-item">
<?php
if ($err_no == -1) { ?>
<p id="info"><?php echo "Connection Error ! Please try again later.\n"; ?></p>
<?php } ?>
<?php
if ($err_no == 0) { ?>
<p id="info"><?php echo "Transaction Successful !\n"; ?></p>
<?php } ?>
<?php
if ($err_no == 1) { ?>
<p id="info"><?php echo "Insufficient Funds !\n";
?></p>
<?php } ?>
<?php
if ($err_no == 2) { ?>
<p id="info"><?php echo "Wrong PIN Entered !\n"; ?></p>
<?php } ?>
</div>
<div class="flex-item">
<a href="atm_simulator.php" class="button">Go Back</a>
</div>
</div>
</body>
</html>