-
Notifications
You must be signed in to change notification settings - Fork 1
/
transfer.php
103 lines (92 loc) · 2.51 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
<?php
session_start();
include 'config.php';
if (!$conn)
{
die("Connection failed");
}
$flag = false;
if (isset($_POST['submit']))
{
$sender = $_SESSION['sender'];
$receiver = $_POST['reciever'];
$amount = $_POST['amount1']; ?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<link rel="preconnect" href="https://fonts.gstatic.com">
</head>
<body>
<!--NAVBAR -->
<nav class="navbar navbar-expand-md navbar-dark bg-primary fixed-top">
</body>
</html>
<?php
$date = date('Y-m-d H:i:s');
$sql = "SELECT amount FROM user WHERE name='$sender'";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while ($row = $result->fetch_assoc())
{
if ($amount > $row["amount"] or $row["amount"] - $amount < 100)
{
echo "<script>swal( 'Error','Insufficient Balance!','error' ).then(function() { window. location = 'profile.php'; });;</script>";
}
else
{
$sql = "UPDATE user SET amount=(amount-$amount) WHERE Name='$sender'";
if ($conn->query($sql) === true)
{
$flag = true;
}
else
{
echo "Error updating record: " . $conn->error;
}
}
}
}
else
{
echo "0 results";
}
if ($flag == true)
{
$sql = "UPDATE user SET amount=(amount+$amount) WHERE name='$receiver'";
if ($conn->query($sql) === true)
{
$flag = true;
}
else
{
echo "Error updating record: " . $con->error;
}
}
if ($flag == true)
{
$sql = "INSERT INTO transfer (`transfer_id`, `sender`, `receiver`, `amount`, `date` ) VALUES (NULL, '$sender','$receiver','$amount', '$date');";
if ($conn->query($sql) === true)
{
}
else
{
echo "Error updating record: " . $conn->error;
}
}
}
if ($flag == true)
{
echo "<script>swal('Transfered!', 'Transaction Successfull','success').then(function() { window. location = 'records.php'; });;</script>";
}
elseif ($flag == false)
{
echo "<script>
$('#text2').show()
</script>";
}
?>