-
Notifications
You must be signed in to change notification settings - Fork 0
/
txndetails.php
51 lines (41 loc) · 1.58 KB
/
txndetails.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
<?php
include './connect.php';
if (isset($_POST['submit'])) {
$from = $_GET['id'];
$to = $_POST['receiver'];
$amount = $_POST['amount'];
$sqlsender = "SELECT * from dummyusers where id=$from";
$query1 = mysqli_query($conn, $sqlsender);
$sql1 = mysqli_fetch_assoc($query1);
$sqlreceiver = "SELECT * from dummyusers where id=$to";
$query2 = mysqli_query($conn, $sqlreceiver);
$sql2 = mysqli_fetch_assoc($query2);
if (($amount) <= 0) {
echo '<script>';
echo 'swal("Txn Not possible!", "payment must be atleast rupee 1 !", "warning")';
echo '</script>';
}
else if ($amount > $sql1['balance']) {
echo '<script>';
echo ' swal("Txn Not possible!", "Amount Too low !!", "warning");';
echo '</script>';
}
else {
$sender = $sql1['name'];
$receiver = $sql2['name'];
$newbalance = $sql1['balance'] - $amount;
$sql = "UPDATE dummyusers set balance=$newbalance where id=$from";
mysqli_query($conn, $sql);
$newbalance = $sql2['balance'] + $amount;
$sql = "UPDATE dummyusers set balance=$newbalance where id=$to";
mysqli_query($conn, $sql);
$sql="INSERT INTO `txnn` (`sender`, `receiver`, `amount`, `date`) VALUES ('$sender','$receiver' , '$amount', CURRENT_TIMESTAMP);";
$query = mysqli_query($conn, $sql);
if ($query) {
echo '<script>';
echo ' swal("SUCCESS!", "Transaction successful !!", "success");';
echo '</script>';
}
}
}
?>