-
Notifications
You must be signed in to change notification settings - Fork 0
/
transferDone.php
73 lines (62 loc) · 2.99 KB
/
transferDone.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
<?php include('db_connect.php'); ?>
<!DOCTYPE html>
<html>
<head>
<title>Completion Status | Banking System</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="css1.css">
</head>
<body>
<?php include('navbar2.php'); ?>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<section style=" background-color:grey;">
<div class="container" style="height: 85vh;margin:3px auto;">
<?php
if($_SERVER["REQUEST_METHOD"]=='POST'){
$sender=$_POST['Sname'];
$receiver=$_POST['Rname'];
$transfer_amount=$_POST['amount'];
if( $sender != $receiver && $transfer_amount>0) {
$senderQuery="SELECT c_balance FROM customer_details WHERE c_name='${sender}'";
$senderConn=mysqli_query($conn, $senderQuery);
$senderResult=mysqli_fetch_array($senderConn);
$senderBalance=$senderResult['c_balance'];
$receiverQuery="SELECT c_balance FROM customer_details WHERE c_name='${receiver}'";
$receiverConn=mysqli_query($conn, $receiverQuery);
$receiverResult=mysqli_fetch_array($receiverConn);
$receiverBalance=$receiverResult['c_balance'];
$senderBalance-=$transfer_amount;
$receiverBalance+=$transfer_amount;
//echo $senderBalance." ".$receiverBalance;
$senderBalanceUpdate="UPDATE customer_details SET c_balance=\"{$senderBalance}\" WHERE c_name=\"{$sender}\"";
$senderLogUpdate=mysqli_query($conn,$senderBalanceUpdate);
$receiverBalanceUpdate="UPDATE customer_details SET c_balance=\"{$receiverBalance}\" WHERE c_name=\"{$receiver}\"";
$receiverLogUpdate=mysqli_query($conn,$receiverBalanceUpdate);
$historyQuery="INSERT INTO transfer_history (t_sender, t_receiver, t_amount) VALUES ('{$sender}', '{$receiver}', {$transfer_amount})";
$historyUpdate=mysqli_query($conn, $historyQuery);
if(!$historyUpdate) {
echo "ERROR!";
}
echo "<h3 class=\"green-text\"> Transaction Successful!</h3>";
echo "<h5>₹{$transfer_amount} has been deducted from your account i.e. {$sender} and the fund is succesfully transfered to {$receiver}.</h5>";
echo "<a href=\"transferHistory.php\" class=\"waves-effect waves-light btn blue\">Transfer History</a>";
echo " <a href=\"index.php\" class=\"waves-effect waves-light btn blue z-depth-2\">Home</a>";
}
else {
echo "<h3 class=\"red-text accent-3\"> Transaction Failed!</h3>";
if($sender==$receiver) {
echo "<h5 class=\"red-text accent-3\">Sender and receiver cannot be the same person.</h5>";
}
else {
echo "<h5 class=\"red-text accent-3\">Transfer amount cannot be negative.</h5>";
}
echo "<p>Redirecting to previous, please wait. <a href=\"transfer.php\">Click here</a> to redirect manually</p>";
header( "refresh:5;url=transfer.php" );
}
}
?>
</div>
</section>
<?php include('footer.php'); ?>
</body>
</html>