-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathminus.php
50 lines (39 loc) · 1.24 KB
/
minus.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
<?php
session_start();
if($_SESSION['user']){
$user=$_SESSION['user'];
}
else{
header("location:index.php");
}
mysql_connect("localhost", "root","") or die(mysql_error());
mysql_select_db("ATM") or die("Cannot connect to database");
$balance=0.00;
$query=mysql_query("SELECT * from Passbook WHERE user='$user'");
while($row=mysql_fetch_array($query))
{
$balance= $balance + $row['amount'];
}
if($_SERVER['REQUEST_METHOD']=="POST")
{
date_default_timezone_set("Africa/Kampala");
$amount=mysql_real_escape_string($_POST['amount']);
if($amount>$balance)
{
Print '<script>alert("You do not have sufficient Funds.");;
window.location.assign("balance.php")</script>';
exit("You have insufficient funds!");
//header("location: balance.php");
}
$amount=(-$amount);
$details=mysql_real_escape_string($_POST['details']);
$time = strftime("%T");
$date = strftime("%B %d, %Y");
mysql_query("INSERT INTO Passbook (amount,date_transaction,details,user) VALUES ('$amount','$date','$details','$user')");
Print '<script>alert("Successful Withdrawal.");window.location.assign("balance.php");</script>';
}
else
{
header("location:home.php");
}
?>