-
Notifications
You must be signed in to change notification settings - Fork 0
/
transfer.php
151 lines (136 loc) · 6.68 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
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Basic Banking System</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<link rel="stylesheet" href ="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link rel="stylesheet" href="path/to/font-awesome/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css2?family=Yusei+Magic&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body id="home">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="index.php"><b>Home</b> <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="customer.php"><b>Customer Details</b></a>
</li>
<li class="nav-item">
<a class="nav-link" href="customerinfo.php"><b>Find Customer</b></a>
</li>
<li class="nav-item">
<a class="nav-link" href="transfer.php"><b>Transfer Money</b></a>
</li>
<li class="nav-item">
<a class="nav-link" href="history.php"><b>History<b></a>
</li>
</ul>
</div>
</nav>
<h1 class="fw-normal head" style="text-align:center;font: italic small-caps bold 36px/2 cursive;">Transfer Money</h1>
<?php include("configuration.php");
$FromName = mysqli_query($connection, "SELECT name FROM customers");
$ToName = mysqli_query($connection, "SELECT name FROM customers");
?>
<form action="" method="GET" id="drop">
<label for="">From:</label>
<select name="fromuser">
<option value="">Choose sender</option>
<?php
while ($name1 = mysqli_fetch_array($FromName)) {
echo "<option value='" . $name1["name"] . "'>" . $name1["name"] . "</option>";
}
?>
</select>
<br> <br>
<label for="">To:</label>
<select name="touser">
<option value="">Choose receiver</option>
<?php
while ($name1 = mysqli_fetch_array($ToName)) {
echo "<option value='" . $name1["name"] . "'>" . $name1["name"] . "</option>";
}
?>
</select> <br><br><label for="">Enter Amount:</label>
<input type="number" name="amount" style="background-color: #fff; color:grey; width:500px; height:50px"
placeholder="Amount"><br><br>
<input class="view" name="transfer" type="submit" value="Transfer"><br>
</form>
<?php
if (isset($_GET['transfer'])) {
$cust1 = $_GET["fromuser"];
$cust2 = $_GET["touser"];
$amount =$_GET["amount"];
// $query = "SELECT balance from customers where name=$cust1";
if ($cust1 != "" && $cust2 != "" && $amount!="")
{
include("configuration.php");
$query = mysqli_query($connection, "SELECT balance FROM customers where name='$cust1'");
$result= mysqli_fetch_assoc($query);
if($cust1==$cust2)
{
echo "<script>alert('Error ! Same Name Selected. Please Check Properly!')</script>";
}
else if($amount<=0)
{
echo "<script>alert('Error ! Amount you entered is too low !')</script>";
}
else if($amount> $result['balance'] )
{
// echo $query;
echo "<script>alert('Insufficient Balance. Transaction failed !')</script>";
}
else if($cust1!=$cust2)
{
// update the balance amount
$receive = "UPDATE customers SET balance = balance + '$amount' WHERE name= '$cust2' ";
$updatedData2 = mysqli_query($connection, $receive);
$send = "UPDATE customers SET balance = balance - '$amount' WHERE name= '$cust1' ";
$updatedData1 = mysqli_query($connection, $send);
if ($updatedData2 && $updatedData1) {
echo "<div class='alert alert-success'>
<h2 style='text-align:center; color:#000' id='h2'>Payment Successfull.</h2>
</div>";
}
else {
echo "<div class='alert alert-warning'>
<h2 style='text-align:center; color:#000' id='h2'>Oops! Payment Unsuccessful. Please Try Again.</h2>
</div>";
}
// insert value into transfer
$transaction = "INSERT INTO transaction(sender,receiver,balance) VALUES ('$cust1', '$cust2', '$amount')";
$done = mysqli_query($connection, $transaction);
if($done){
$u1 = "SELECT * FROM customers WHERE name='$cust1' ";
$res=mysqli_query($connection,$u1);
$row_count=mysqli_num_rows($res);
}
}
}
else {
echo "<script>alert('Please Enter All the required fields.')</script> ";
}
}
?>
<footer class="bg-light text-center text-lg-start">
<div class="text-center p-3" style="background-color: rgba(0, 0, 0, 0.2)">
© 2021 Copyright
<a class="text-dark" href="index.php">By Prodeep Kumar Paul</a>
</div>
<!-- Copyright -->
</footer>
</body>
</html>