-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.php
57 lines (49 loc) · 1.61 KB
/
config.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
<?php
$conn = mysqli_connect("localhost","root","","banking");
if($conn -> connect_error){
die("connection failed:".$conn->connect_error);
}
$sender = $_POST['sender'];
$receiver = $_POST['receiver'];
$amount = $_POST['amount'];
$q1="SELECT EXISTS(SELECT * from customers WHERE id=$sender)" ;
$q2="SELECT EXISTS(SELECT * from customers WHERE id=$receiver)";
$res1 = $conn -> query($q1);
$row1 = $res1-> fetch_assoc();
$res2 = $conn -> query($q2);
$row2 = $res2-> fetch_assoc();
if ($row1["EXISTS(SELECT * from customers WHERE id=$sender)"]==1 && $row2["EXISTS(SELECT * from customers WHERE id=$receiver)"]==1)
{
$q6= "select Balance from customers where id= '$sender'";
$res6 = $conn -> query($q6);
$row6 = $res6-> fetch_assoc();
if ($row6["Balance"] < $amount)
{
header( "refresh:5 ;url=details.php");
echo "Transaction failed!! Can't transfer the amount to transfer";
echo "\nPlease wait... Redirecting to the site";
}
else
{
$q3 = "UPDATE customers
set Balance = Balance - '$amount'
where id = '$sender';";
mysqli_query($conn,$q3);
$q4 = "UPDATE customers
set Balance = Balance + '$amount'
where id = '$receiver';";
mysqli_query($conn,$q4);
$q5 = "insert into transfers (Sender , Receiver , Amount) values ('$sender','$receiver','$amount')";
mysqli_query($conn,$q5);
header( "refresh:5 ;url=details.php");
echo "Transaction Successful";
echo "\nPlease wait...Redirecting to the site";
}
}
else
{
header( "refresh:5 ;url=details.php");
echo "Transaction failed!!";
echo "\nPlease wait...Redirecting to the site";
}
?>