-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpayment.php
62 lines (54 loc) · 2.14 KB
/
payment.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
<!DOCTYPE html>
<html>
<head>
<title>Payment</title>
<!-- <meta name="viewport" content="width=device-width, height=device-width, initial-scale=1.0"> -->
</head>
<body>
</body>
</html>
<?php
include "display.php";
include "connection.php";
if (isset($_POST['submit']))
{
$to=$_POST['to'];
$from=$_POST['from'];
$amount=$_POST['amount'];
$qury="INSERT INTO history VALUES ('$from','$to','$amount')";
mysqli_query($conn,$qury);
$newmoney1=0;
$newmoney2=0;
$sql="SELECT credit FROM USERS WHERE name = '$to'";
$data=mysqli_query($conn,$sql);
$res1=mysqli_fetch_array($data);
$sql="SELECT credit FROM USERS WHERE name = '$from'";
$data=mysqli_query($conn,$sql);
$res2=mysqli_fetch_array($data);
$newmoney1 = ($res1['credit'] + (int)$amount);
$newmoney2 = ($res2['credit'] - (int)$amount);
if($res2['credit']<$amount && $amount>$res1['credit'])
{
echo '<script>alert("enter correct amount")</script>';
}
else if((!(is_numeric($_POST['amount'])) || $_POST['amount'] == 0 || $_POST['amount'] == " "))
{
echo '<script>alert("Error cannot transfer credits")</script>';
}
else if($_POST['to'] === 'null' || $_POST['from'] === 'null' ) {
echo '<script>alert("select user name c")</script>';
}
else if($_POST['to']== $_POST['from']){
echo '<script>alert("cant transfer to urself")</script>';
}
else
{
$sql="UPDATE users SET credit='$newmoney1' WHERE name='$to';";
mysqli_query($conn,$sql);
$sql="UPDATE users set credit='$newmoney2' WHERE name='$from';";
mysqli_query($conn,$sql);
//echo "Credits Transfered";
echo '<script>alert("Transfer Successufully....")</script>';
}
}
?>