-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransferMoney_one.php
156 lines (129 loc) · 4.77 KB
/
TransferMoney_one.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
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Banking System</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/style.css" rel="stylesheet">
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<?php
include 'header.php';
?>
</head>
<?php
include 'commonSql.php';
if(isset($_POST['submit']))
{
$from = $_GET['id'];
$to = $_POST['to'];
$amnt = $_POST['amount'];
$sql = "SELECT * from customertb where id=$from";
$query = mysqli_query($con,$sql);
$sql1 = mysqli_fetch_array($query); //sender's account
$sql = "SELECT * from customertb where id=$to";
$query = mysqli_query($con,$sql);
$sql2 = mysqli_fetch_array($query);//reciever's account
//insufficient balance
if($amnt > $sql1[3])
{
echo '<script type="text/javascript">';
echo ' alert("Insufficient Balance")';
echo '</script>';
}
else if($amnt == 0){
echo "<script type='text/javascript'>alert('Amount should be Greater than Zero');
</script>";
}
else {
//transaction begins
$newCredit =$sql1[3] -$amnt;
$sql = "UPDATE customertb set credits=$newCredit where id=$from";
mysqli_query($con,$sql);
$newCredit =$sql2[3] +$amnt;
$sql = "UPDATE customerTb set credits=$newCredit where id=$to";
mysqli_query($con,$sql);
//inserting records in recordsTB
$sender = $sql1['Name'];
$receiver = $sql2['Name'];
$det="INSERT INTO RecordsTb('sender', 'receiver', 'credits') VALUES ('$sender','$receiver','$amnt')";
$detsubmit=mysqli_query($con,$det);
if($det){
echo "<script type='text/javascript'>
alert('Transaction Successfull!');
</script>";
}
$newCredit= 0;
$amnt =0;
}
}
//window.location='transaction.php';
?>
<body>
<div class="container ">
<h2>Transaction here</h2>
<?php
include 'commonSql.php';
$sid=$_GET['id'];
$sql = "SELECT * FROM customertb where id=$sid";
$query=mysqli_query($con,$sql);
if(!$query)
{
echo "Error ".$sql."<br/>".mysqli_error($con);
}
$rows=mysqli_fetch_array($query);
?>
<form method="post" name="tcredit" class="tabletext" ><br/>
<label> From: </label><br/>
<div>
<table class="table roundedCorners tabletext table-hover table-striped table-condensed astyle" >
<tr>
<th>Id</th>
<th>Email</th>
<th>Name</th>
<th>Amount</th>
</tr>
<tr>
<td><?php echo $rows[0] ?></td>
<td><?php echo $rows[1] ?></td>
<td><?php echo $rows[2] ?></td>
<td><?php echo $rows[3] ?></td>
</tr>
</table>
</div>
<br/><br/><br/>
<label>To:</label>
<select class=" form-control" name="to" style="margin-bottom:5%;" required>
<option value="" disabled selected> </option>
<?php
include 'config.php';
$sid=$_GET['id'];
$sql = "SELECT * FROM customertb where id!=$sid";
$query=mysqli_query($con,$sql);
if(!$query)
{
echo "Error ".$sql."<br/>".mysqli_error($con);
}
while($rows = mysqli_fetch_array($query)) {
?>
<option class="table text-center table-striped " value="<?php echo $rows['id'];?>" >
<?php echo $rows[2] ;?>
<!--(Credits:
<?php echo $rows[3] ;?> )-->
</option>
<?php
}
?>
</select> <br/><br/><br/>
<label>Amount:</label>
<input type="number" id="amm" class="form-control" name="amount" min="0" required /> <br/><br/>
<div class="text-center btn3" >
<button class="btn btn-success btn-lg active" name="submit" type="submit" id="mybtn" style="margin-left:5%">Proceed</button>
</div>
</form>
</div>
</body>
</html>