-
Notifications
You must be signed in to change notification settings - Fork 1
/
transact.php
65 lines (62 loc) · 1.71 KB
/
transact.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
<?php
include 'connection.php';
$sender=$_POST['sender'];
$receiver=$_POST['receiver'];
$amount=$_POST['amount'];
if($sender==$receiver)
{
echo("
<script>
alert('Something Went Wrong!!!Please Try Again')
window.location.href='index.html'
</script>
");
}
else
{
$select="SELECT * from users where Name='$sender'";
$query1=$connection->query($select);
$res=mysqli_fetch_array($query1);
if($res['Balance']<$amount)
{
echo("
<script>
alert('Something Went Wrong!!!Please Try Again')
window.location.href='index.html'
</script>
");
}
else
{
$money1=$res['Balance']-$amount;
$select1="UPDATE users set Balance='$money1' where Name='$sender' ";
$query1=$connection->query($select1);
$select2="SELECT * from users where Name='$receiver'";
$query2=$connection->query($select2);
$res2=mysqli_fetch_array($query2);
$money2=$res2['Balance']+$amount;
$select3="UPDATE users set Balance='$money2' where Name='$receiver' ";
$query3=$connection->query($select3);
if($query1 && $query3)
{
$insert="INSERT INTO Transactions SET Sender='$sender' ,Receiver='$receiver' , Amount='$amount'";
$query4=$connection->query($insert);
echo("
<script>
alert('Success')
window.location.href='viewuser.php'
</script>
");
}
else
{
echo("
<script>
alert('Something Went Wrong!!!Please Try Again')
window.location.href='index.html'
</script>
");
}
}
}
?>