-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.php
136 lines (113 loc) · 4.41 KB
/
database.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<div class="database">
<?php
// if (isset($_SESSION["username"])){
// } else{
// header('Location: home.php');
// }
class Database{
public $servername;
public $dbuser;
public $dbpassword;
public $dbname;
public $conn;
// function __construct($serverName){
// echo "Welcome to our site<br>";
// }
// function __destruct(){
// echo "Thank You<br>";
// }
function conn(){
$this->servername = "localhost";
$this->dbuser = "root";
$this->dbpassword = "";
$this->dbname = "bank";
$this->conn = new mysqli($this->servername,$this->dbuser,$this->dbpassword,$this->dbname);
if ($this->conn->connect_error){
die("Connection failed: ".$conn->connect_error);
} else{
// echo "connected successfully<br>";
}
}
//======================================QUERY======================================
public $query;
public $book;
function knowCredit($cust){
$this->query = "SELECT `credit`
FROM `accounts`
WHERE `id` = '$cust'
OR `name`= '$cust'
OR `visaNum`= '$cust'";
$result=$this->conn->QUERY($this->query);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$oldCredit = $row["credit"];
return $oldCredit;
}
}
}
function deposit($cust, $value){
$oldCredit = $this-> knowCredit($cust);
$newCredit = $oldCredit + $value;
$this->query = "UPDATE `accounts`
SET `credit`='$newCredit'
WHERE `name`= '$cust'
OR `id`='$cust'";
$result=$this->conn->QUERY($this->query);
echo '<span style="font-size:25px;">new credit = '.$newCredit.'</span>';
}
function withdraw($cust, $value){
$oldCredit = $this-> knowCredit($cust);
if ($oldCredit >= $value){
$newCredit = $oldCredit - $value;
$this->query = "UPDATE `accounts`
SET `credit`='$newCredit'
WHERE `name`= '$cust'
OR `id`='$cust'";
$result=$this->conn->QUERY($this->query);
echo '<span style="font-size:25px;">new credit = '.$newCredit.'</span>';
} else{
echo "<span style='font-size:25px;'>not enough balance</span>";
}
}
function withdraw2($visaNum, $visaPassword, $value){
if ($this->checkCust($visaNum, $visaPassword) == true){
$oldCredit = $this-> knowCredit($visaNum);
if ($oldCredit >= $value){
$newCredit = $oldCredit - $value;
$this->query = "UPDATE `accounts`
SET `credit`='$newCredit'
WHERE `visaNum`= '$visaNum'";
$result=$this->conn->QUERY($this->query);
echo '<span style="font-size:25px;">new credit = '.$newCredit.'</span>';
} else{
echo "<span style='font-size:25px;'>not enough balance</span>";
}
}else{
echo '<span style="font-size:25px;">Wrong Visa number or password</span>';
}
}
function checkCust($visaNum, $visaPass){
$this->query = "SELECT *
FROM `accounts`
WHERE `visaNum` = '$visaNum'
AND `visaPass`= '$visaPass'";
$result=$this->conn->QUERY($this->query);
if ($result->num_rows > 0) {
return true;
}
return false;
}
function customers(){
$this->query = "SELECT *
FROM `accounts`
ORDER BY `credit`DESC";
$result=$this->conn->QUERY($this->query);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo '<span style="font-size:25px;">'.$row["name"].' || '.$row["credit"].'</span><br>';
}
}
}
}
?>
</div>