forked from Piyushhbhutoria/FinTech
/
subwallet.php
executable file
·48 lines (48 loc) · 1.34 KB
/
subwallet.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
<?php
session_start();
include('config.php');
$useruid = $_SESSION['log']['uid'];
$amt = $_POST['amount'];
$file = 'count.txt';
//get the number from the file
$uniq = file_get_contents($file);
//add +1
$uid = $uniq + 1 ;
// add that new value to text file again for next use
file_put_contents($file, $uid);
$qry = mysqli_query($con,"SELECT * FROM wallet WHERE useruid='$useruid' ")or die(mysqli_error());
$row = mysqli_fetch_array($qry);
if($row['balance'] >= $amt)
{
$balance = $row['balance']-$amt;
$sql = mysqli_query($con,"UPDATE wallet SET balance='$balance' WHERE useruid='$useruid' ")or die(mysqli_error());
$sql1 = mysqli_query($con,"INSERT INTO transaction (useruid, amount, type, transuid, balance) VALUES ('$useruid', '$amt', 'debit', '$uid','$balance' ) ")or die(mysqli_error());
if($sql)
{
?>
<script>
alert("Money Transfered Successfully!");
window.location.href = "dashboard.php";
</script>
<?php
}
else
{
?>
<script>
alert("Money unable to Transfer!");
window.location.href = "dashboard.php";
</script>
<?php
}
}
else
{
?>
<script>
alert("Add Money to wallet first");
window.location.href = "dashboard.php";
</script>
<?php
}
?>