-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers.php
212 lines (175 loc) · 7.88 KB
/
users.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
include 'connect.php';
if(isset($_POST['submit']))
{
$from = $_GET['id'];
$to = $_POST['to'];
$amount = $_POST['amount'];
$sql = "SELECT * from users where id=$from";
$query = mysqli_query($conn,$sql);
$sql1 = mysqli_fetch_array($query);
$sql = "SELECT * from users where id=$to";
$query = mysqli_query($conn,$sql);
$sql2 = mysqli_fetch_array($query);
//Conditions
//For negative value
if (($amount)<0)
{
echo '<script type="text/javascript">';
echo ' alert("Negative value cannot be transferred !")';
echo '</script>';
}
//Insufficient balance
else if($amount > $sql1['balance'])
{
echo '<script type="text/javascript">';
echo ' alert("Sorry! you have insufficient balance !")';
echo '</script>';
}
//For 0 (zero) value
else if($amount == 0){
echo "<script type='text/javascript'>";
echo "alert('Zero value cannot be transferred !')";
echo "</script>";
}
else {
$newbalance = $sql1['balance'] - $amount;
$sql = "UPDATE users set balance=$newbalance where id=$from";
mysqli_query($conn,$sql);
$newbalance = $sql2['balance'] + $amount;
$sql = "UPDATE users 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 Successfully !');
window.location='history.php';
</script>";
}
$newbalance= 0;
$amount =0;
}
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<title>MANI BANK</title>
<link rel="stylesheet" href="css/style2.css">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@500&display=swap" rel="stylesheet">
</head>
<body>
<!-- Nav bar -->
<nav class="navbar py-2 navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#"><img src="logos/logo.webp" alt="Bank" width="50" height="50" style="margin-right:10px">MANI BANK </a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-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 me-auto mb-8 mb-lg-0">
<li class="nav-item py-3">
<a class="nav-link" aria-current="page" href="index.php"><strong>Home</strong></a>
</li>
<li class="nav-item py-3">
<a class="nav-link" href="money.php">Money Transfer</a>
</li>
<li class="nav-item py-3 ">
<a class="nav-link " href="history.php"> Transaction History</a>
</li>
</ul>
</div>
</div>
</nav>
<class class="welcome">
<h2>
<img src="logos/m1.webp" alt="Bank" width="75" height="75" style="font-weight: bold;"> <strong>Money
Transfer</strong> <img src="logos/m2.webp" alt="Bank" width="75" height="75">
</h2>
</class>
<!-- Table -->
<div class="container">
<h2 class="text-center pt-4" style="color : black;">Customer Details</h2>
<?php
include 'connect.php';
$sid=$_GET['id'];
$sql = "SELECT * FROM users where id=$sid";
$result=mysqli_query($conn,$sql);
if(!$result)
{
echo "Error : ".$sql."<br>".mysqli_error($conn);
}
$rows=mysqli_fetch_assoc($result);
?>
<form method="post" name="tcredit" class="tabletext" ><br>
<div>
<table class="table table-striped table-hover">
<tr style="color : black;" class="table-primary">
<th class="text-center">Id</th>
<th class="text-center">Name</th>
<th class="text-center">Email</th>
<th class="text-center">Balance</th>
</tr>
<tr style="color : black;">
<td class=" text-center py-2"><?php echo $rows['id'] ?></td>
<td class=" text-center py-2"><?php echo $rows['name'] ?></td>
<td class=" text-center py-2"><?php echo $rows['email'] ?></td>
<td class=" text-center py-2"><?php echo $rows['balance'] ?></td>
</tr>
</table>
</div>
<h2 class="text-center pt-4" style="color : black;">Transer Money Here !</h2>
<label style="color : black;"><strong>Transfer To:</strong></label>
<select name="to" class="form-control" required>
<option value="" disabled selected>Choose</option>
<?php
include 'connect.php';
$sid=$_GET['id'];
$sql = "SELECT * FROM users where id!=$sid";
$result=mysqli_query($conn,$sql);
if(!$result)
{
echo "Error ".$sql."<br>".mysqli_error($conn);
}
while($rows = mysqli_fetch_assoc($result)) {
?>
<option class="table" value="<?php echo $rows['id'];?>" >
<?php echo $rows['name'] ;?> (Balance:
<?php echo $rows['balance'] ;?> )
</option>
<?php
}
?>
<div>
</select>
<br>
<label style="color : black;"><strong>Amount:</strong></label>
<input type="number" class="form-control" name="amount" required>
<br><br>
<div class="text-center" >
<button class="btn btn-primary mb-3" name="submit" type="submit" id="myBtn" >Fill the Amount and Transfer</button>
</div>
</form>
</div>
<!-- Optional JavaScript; choose one of the two! -->
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW"
crossorigin="anonymous"></script>
<!-- Option 2: Separate Popper and Bootstrap JS
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js" integrity="sha384-q2kxQ16AaE6UbzuKqyBE9/u/KzioAlnx2maXQHiDX9d4/zp8Ok3f+M7DPm+Ib6IU" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.min.js" integrity="sha384-pQQkAEnwaBkjpqZ8RU1fF1AKtTcHJwFl3pblpTlHXybJjHpMYo79HY3hIi4NKxyj" crossorigin="anonymous"></script>
-->
</body>
</html>