-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.php
More file actions
177 lines (94 loc) · 4.91 KB
/
Copy pathedit.php
File metadata and controls
177 lines (94 loc) · 4.91 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
session_start();
if(!$_SESSION['user']=='admin' || !$_SESSION['user']=='staff'){
header("Location: index.php");
}
$obj = new EditRoom();
$obj->updateRoom();
class EditRoom{
private $roomID;
private $newPrice;
private $conn;
private $rs;
private $rs1;
private $rs2;
private $roomName;
private $roomPrice;
private $username;
private $pass;
private $pass2;
private $password;
public function __construct() {
require 'dbconnection.php';
$this->conn = new dbconnection();
$this->roomID = filter_input(INPUT_POST, id);
$this->newPrice = filter_input(INPUT_POST, new_price);
$this->roomName = strtoupper(filter_input(INPUT_POST, roomName));
$this->roomPrice = filter_input(INPUT_POST, roomPrice);
$this->username = filter_input(INPUT_POST, username);
$this->pass = filter_input(INPUT_POST, pass);
$this->pass2 = filter_input(INPUT_POST, repass);
}
public function updateRoom(){
if (isset($this->roomID)&& !empty($this->roomID)){
$_SESSION['roomID']= $this->roomID;
$this->conn->query("SELECT * FROM rooms WHERE room_id=:id");
$this->conn->bind(':id', $this->roomID);
$this->conn->execute();
$this->rs= $this->conn->resultSet();
if($this->rs){
foreach ($this->rs as $row){
echo "Room Name : " . strtoupper($row['room_name']);
}
}else {
echo 'Aww something is wrong could not fetch data ';
}
}
elseif (isset($this->newPrice) && !empty($this->newPrice) && isset($_SESSION['roomID'] ) ){
$this->conn->query("UPDATE rooms SET room_price=:price WHERE room_id=:id");
$this->conn->bind(':id', $_SESSION['roomID']);
$this->conn->bind(':price', $this->newPrice);
$this->conn->execute();
$this->rs1= $this->conn->resultSet();
if($this->rs1){
echo 'Room Price Updated Succesfully';
unset($_SESSION['roomID']);
}else{
echo 'Aww something is wrong could not update ' ;
unset($_SESSION['roomID']);
}
}
elseif (isset($this->roomName) && isset($this->roomPrice) &&!empty ($this->roomName) && !empty ($this->roomPrice)){
$this->conn->query("INSERT INTO rooms (room_name ,room_price) VALUES (:roomName,:roomPrice) RETURNING room_name");
$this->conn->bind(':roomName', $this->roomName);
$this->conn->bind(':roomPrice', $this->roomPrice);
$this->conn->execute();
$this->rs2= $this->conn->resultSet();
if($this->rs2){
echo 'Room Added Succesfully';
}else{
echo 'Aww something is wrong could not update ' ;
}
}
elseif (isset($this->username) && isset($this->pass) && isset($this->pass2) && !empty($this->username) && !empty($this->pass) && !empty($this->pass2)){
if($this->pass == $this->pass2){
$this->conn->query("INSERT INTO users (uname, pwd) VALUES (:uname,:pwd) RETURNING id");
$this->conn->bind(':uname', $this->username);
$this->conn->bind(':pwd', $this->pass);
$this->conn->execute();
$this->rs2= $this->conn->resultSet();
if($this->rs2){
echo $this->username .' Added Succesfully';
}else{
echo 'Aww something is wrong could not update ' ;
}
}else {
echo 'Passwords do not Match';
}
}
else{
echo 'Some field(s) empty !';
}
}
}
?>