-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransfer1.php
More file actions
118 lines (74 loc) · 2.46 KB
/
transfer1.php
File metadata and controls
118 lines (74 loc) · 2.46 KB
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
<?php
ini_set('display_errors','on');
$servername = "localhost";
$username = "root";
$password = "root123";
$dbname = "bank";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if ($conn->connect_error)
die("Connection failed: " . $conn->connect_error);
mysqli_autocommit($conn, FALSE);
$s=mysqli_real_escape_string($conn, $_POST['sender']);
$r =mysqli_real_escape_string($conn, $_POST['reciever']);
$a = mysqli_real_escape_string($conn, $_POST['amount']);
$sql = mysqli_query($conn,"INSERT INTO transaction (sender_name, rcvr_name, amount) VALUES ('$s', '$r', '$a')");
if ($_POST['submit'] && is_numeric($_POST['amount']))
{
// add $$ to reciever
$result = mysqli_query($conn, "UPDATE customer SET balance = balance + '". $_POST['amount'] . "' WHERE Name ='" .$_POST['reciever'] ."'" );
if ($result !== TRUE) {
mysqli_rollback($conn);
}
// subtract $$ from sender
$result = mysqli_query($conn, "UPDATE customer SET balance = balance - '". $_POST['amount']. "' WHERE Name = '" . $_POST['sender']. "'");
if ($result !== TRUE) {
mysqli_rollback($conn);
}
mysqli_commit($conn);
}
// get account balances
// save in array, use to generate form
$result = mysqli_query($conn, "SELECT * FROM customer");
while ($row = mysqli_fetch_assoc($result)) {
$customer[] = $row;
}
// close connection
mysqli_close($conn);
?>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="IE=edge, chrome=">
<title> Transaction </title>
<link rel="stylesheet" href="header.css">
<link rel="stylesheet" href="transfer.css">
</head>
<body onload="myFunction()">
<div id="wrapper">
<?php
include "./header.html"
?>
</div>
<div id="wrap">
<div id="snackbar">Transaction Successful....</div>
<table border=1>
<?php
echo "<caption>Account Details</caption>";
foreach ($customer as $c) {
echo "<tr><td>" . $c['Name'] . "</td><td>" . $c['Email_ID'] . "</td><td>" . $c['balance'] . "</td></tr>";
}
?>
</table>
<div id="but">
<button class="trans" onclick="location.href='history.php'">View Transaction History</button>
</div>
</div>
<script>
function myFunction() {
var x = document.getElementById("snackbar");
x.className = "show";
setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
}
</script>
</body>
</html>