-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction.php
108 lines (64 loc) · 2.75 KB
/
transaction.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
<?php
include "connect.php";
session_start();
?>
<!DOCTYPE html>
<html lang = "en">
<head>
<title>Credit Management</title>
<meta charset = "utf-8">
<meta name = "viewport" content = "width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class = "jumbotron jumbotron-fluid">
<div class = "container">
<?php
$select_name = htmlspecialchars($_POST["select_name"]);
$user_name = htmlspecialchars($_SESSION["username"]);
$amount = htmlspecialchars($_POST["amount"]);
$sql = "SELECT current_credit from USER where name = '$user_name'";
$sql2 = "SELECT current_credit from USER where name = '$select_name'";
global $conn;
$result = $conn->query($sql);
$balance = $result->fetch_assoc()["current_credit"];
$previousBalance = $balance;
$result = $conn->query($sql2);
$deposit = $result->fetch_assoc()["current_credit"];
if($balance > $amount && $amount > 0){
$balance -= $amount;
$deposit += $amount;
$sql1 = "UPDATE USER SET current_credit = $balance WHERE name = '$user_name'";
$sql2 = "UPDATE USER SET current_credit = $deposit WHERE name = '$select_name'";
$sql3 = "INSERT INTO transaction (name,sendTo,sendAmount,status) values ('$user_name','$select_name',$amount,'send')";
$sql4 = "INSERT INTO transaction (name,receivedFrom,receivedAmount,status) values ('$select_name','$user_name',$amount,'received')";
mysqli_autocommit($conn,FALSE);
$conn->query($sql1);
$conn->query($sql2);
$conn->query($sql3);
$conn->query($sql4);
if(mysqli_commit($conn)){
echo "<h2>Transaction Successful</h2>";
echo "<h4> Previous credit = ".$previousBalance."<h4>";
echo "<h4> Updated Credit = $balance</h2>";
}else{
echo "<h2>Not Sufficient Balance to do Transaction.</h2>";
}
}else if($amount < 0){
echo "<h2>Oops there is no money flowing backward</h2>";
echo "<h4>Please enter the positive credit</h2>";
}
else{
echo "<h2>Insufficient Balance to do Transaction.</h2>";
echo "<h2>Your Balance $balance";
}
$conn->close();
echo "<br><a href =". '"logout.php"'.">Go Back</a>";
?>
</div>
</div>
</body>
</html>