-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransfer.php
176 lines (169 loc) · 5.53 KB
/
transfer.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
include('connection.php');
if(isset($_POST['submit']))
{
$from = $_GET['id'];
$to = $_POST['to'];
$amount = $_POST['amount'];
$sql = "SELECT * from customers where id=$from";
$query = mysqli_query($conn,$sql);
$sql1 = mysqli_fetch_array($query);
$sql = "SELECT * from customers where id=$to";
$query = mysqli_query($conn,$sql);
$sql2 = mysqli_fetch_array($query);
if (($amount)<0)
{
echo '<script type="text/javascript">';
echo ' alert("Negative values cannot be transferred")';
echo '</script>';
}
else if($amount > $sql1['balance'])
{
echo '<script type="text/javascript">';
echo ' alert("Insufficient Balance")';
echo '</script>';
}
else if($amount == 0){
echo "<script type='text/javascript'>";
echo "alert('Oops! Zero value cannot be transferred')";
echo "</script>";
}
else {
$newbalance = $sql1['balance'] - $amount;
$sql = "UPDATE customers set balance=$newbalance where id=$from";
mysqli_query($conn,$sql);
$newbalance = $sql2['balance'] + $amount;
$sql = "UPDATE customers set balance=$newbalance where id=$to";
mysqli_query($conn,$sql);
$sender = $sql1['name'];
$receiver = $sql2['name'];
$sql = "INSERT INTO transaction(`sender`, `receiver`, `balance`) VALUES ('$sender','$receiver','$amount')";
$query=mysqli_query($conn,$sql);
if($query){
echo "<script> alert('Transaction Successful');
window.location='customer.php';
</script>";
}
$newbalance= 0;
$amount =0;
}
}
?>
<?php
$id = (isset($_GET['id']) ? $_GET['id'] : '');
$sql = "SELECT * from `customers` WHERE id=$id";
$result = mysqli_query($conn, $sql);
if($result){
while($res = mysqli_fetch_assoc($result)){
$balance = $res['balance'];
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Money Transfer</title>
<link rel="stylesheet" href="Main.css">
<style>
body{
background-image: url(card.jpg);
background-size: cover;
}
a:link, a:visited
{
background-color: rgb(8, 8, 65);
color: white;
text-decoration: none;
}
a:hover
{
background-color: whitesmoke;
color: black;
}
#outside {
padding-top: 25px;
padding-bottom: 25px;
}
h1 {
font-size: 1.5em;
text-align: center;
}
form {
margin: auto;
width: 70%;
padding: 1em;
border: 3px solid navy;
border-radius: 1em;
}
input, select{
width: 50%;
text-align:center;
font-family: Trebuchet MS;
font-size: 18px;
}
#transaction{
background-color: whitesmoke;
opacity: 0.75;
font-family: Trebuchet MS;
font-size: 25px;
}
fieldset {
border:3px solid goldenrod;
margin: 10px;
}
legend {
font-weight: 700;
color: rgb(8,8,65);
}
button{
background-color: rgb(8, 8, 65);
padding: 5px;
font-size: 18px;
font-family: Trebuchet MS;
color: white;
border-radius: 6px;
}
</style>
</head>
<body>
<div class="Title">Ace Finance</div>
<div class="navigation">
<a href="home.php">Home</a>
<a href="customer.php">Customer</a>
<a href="transaction.php">Transaction</a>
</div>
<div id="outside">
<form id="transaction" action="transfer.php?id=<?php echo $id?>" method="POST" align="center">
<h1>Make Money Transfer</h1>
<fieldset>
<legend>Transfer Details</legend>
<label id="name-label" for="name">Transfer to:</label>
<select name="to" class="form-control" required>
<option value="" disabled selected>Choose</option>
<?php
$sid=$_GET['id'];
$sql = "SELECT * FROM customers where id!=$sid";
$result=mysqli_query($conn,$sql);
if(!$result)
{
echo "Error ".$sql."<br>".mysqli_error($conn);
}
while($rows = mysqli_fetch_assoc($result)) {
?>
<option value="<?php echo $rows['id'];?>" >
<?php echo $rows['name'] ;?>
(Balance: <?php echo $rows['balance'] ;?> )
</option>
<?php
}
?>
</select>
<p><label>Amount:</label>
<input type="number" name="amount" required></p>
<button name="submit" type="submit">Transfer</button> </div>
</form>
</div>
</body>
</html>