-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_wishlist.php
236 lines (229 loc) · 9.63 KB
/
remove_wishlist.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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
//Turn on error reporting
ini_set('display_errors', 'On');
//Connects to the database
$mysqli = new mysqli("oniddb.cws.oregonstate.edu", "depreyj-db", "hed5gVlymx3PJKO7", "depreyj-db");
if($mysqli->connect_errno){
echo "Connection error " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
if(!($stmt = $mysqli->prepare("DELETE w, wp
FROM wishlists AS w INNER JOIN wishlist_props AS wp ON w.list_id = wp.list_id
INNER JOIN guests AS g ON g.guest_id = w.guest_id
WHERE g.fname = ? && g.lname = ? && w.listname = ?"))){
echo "Prepare failed: " . $stmt->errno . " " . $stmt->error;
}
if(!($stmt->bind_param("sss", $_POST['first_name'], $_POST['last_name'], $_POST['listname']))){
echo "Bind failed: " . $stmt->errno . " " . $stmt->error;
}
if(!$stmt->execute()){
echo "Execute failed: " . $stmt->errno . " " . $stmt->error;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Your Wishlists</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<ul class="nav nav-tabs">
<li>
<a href="index.php">Home</a>
</li>
<li class="active">
<a href="guest.php">Guests</a>
</li>
<li>
<a href="host.php">Hosts</a>
</li>
</ul>
</li>
</ul>
<div class="jumbotron well">
<h2>
Your Wishlists
</h2>
<p>
View Favorite Properties
</p>
</div><span class="label label-default"></span>
</div>
</div>
</div>
<div class="container">
<h2>Your Wishlists</h2>
<div class="table-responsive">
<table class="table table-condensed">
<tr>
<th>List ID</th>
<th>List Name</th>
</tr>
<?php
if(!($query = $mysqli->prepare(
"SELECT wishlists.list_id as 'ID no.', listname as 'My Wishlists'
FROM wishlists
INNER JOIN guests g ON g.guest_id = wishlists.guest_id
WHERE g.fname = ? && g.lname = ?"))){
echo "Prepare failed: " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
if(!($query->bind_param("ss", $_POST['first_name'], $_POST['last_name']))){
echo "Bind failed: " . $query1->errno . " " . $query1->error;
}
if(!($query->execute())){
echo "Execute failed: " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
if(!($query->bind_result($list_id, $listname))){
"Bind failed: " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
while ($query->fetch()){
echo "<tr>\n<td>" . $list_id . "\n</td>\n<td>" . $listname . "\n</td>\n</tr>";
}
$query->close();
?>
</table>
</div>
</div>
<div class="container">
<h2>Remove Wishlist</h2>
<form action="remove_wishlist.php" method="post" role="form" class="form-horizontal">
<div class="form-group">
<div class="col-sm-3"><label>Select List</label>
<select id="listname" name="listname" class="form-control">
<?php
if(!($stmt = $mysqli->prepare("SELECT wishlists.listname
FROM wishlists
INNER JOIN guests g ON g.guest_id = wishlists.guest_id
WHERE g.fname = ? && g.lname = ?"))){
echo "Prepare failed: " . $stmt->errno . " " . $stmt->error;
}
if(!($stmt->bind_param("ss", $_POST['first_name'], $_POST['last_name']))){
echo "Bind failed: " . $query1->errno . " " . $query1->error;
}
if(!$stmt->execute()){
echo "Execute failed: " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
if(!$stmt->bind_result($listname)){
echo "Bind failed: " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
while($stmt->fetch()){
echo '<option value="'.$listname.'"> ' . $listname . '</option>\n';
}
$stmt->close();
?>
</select>
</div>
<div class="col-sm-1"><label>Guest</label><input type="text" readonly="readonly" id="first_name" name="first_name" class="form-control" value=<?php echo $_POST['first_name']; ?> ></div>
<div class="col-sm-1"><label>Name</label><input type="text" readonly="readonly" id="last_name" name="last_name" class="form-control" value=<?php echo $_POST['last_name']; ?> ></div>
</div>
<div class="col-sm-3">
<button type="submit" class="btn btn-danger pull-left">Remove It</button>
</div>
</div>
</form>
<hr>
</div>
<div class="container">
<h2>Add to Wishlist</h2>
<form action="wishlist_it.php" method="post" role="form" class="form-horizontal">
<div class="form-group">
<div class="col-sm-3"><label>Select Property</label>
<select id="prop_id" name="prop_id" class="form-control">
<?php
if(!($stmt = $mysqli->prepare("SELECT prop_id
FROM properties
ORDER BY prop_id"))){
echo "Prepare failed: " . $stmt->errno . " " . $stmt->error;
}
if(!$stmt->execute()){
echo "Execute failed: " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
if(!$stmt->bind_result($prop_id)){
echo "Bind failed: " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
while($stmt->fetch()){
echo '<option value="'.$prop_id.'"> ' . $prop_id . '</option>\n';
}
$stmt->close();
?>
</select>
</div>
<div class="col-sm-3"><label>Select List</label>
<select id="listname" name="listname" class="form-control">
<?php
if(!($query = $mysqli->prepare(
"SELECT listname
FROM wishlists
INNER JOIN guests g ON g.guest_id = wishlists.guest_id
WHERE g.fname = ? && g.lname = ?"))){
echo "Prepare failed: " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
if(!($query->bind_param("ss", $_POST['first_name'], $_POST['last_name']))){
echo "Bind failed: " . $query1->errno . " " . $query1->error;
}
if(!($query->execute())){
echo "Execute failed: " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
if(!($query->bind_result($listname))){
"Bind failed: " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
while ($query->fetch()){
echo '<option value="'.$listname.'"> ' . $listname . '</option>\n';
}
$query->close();
?>
</select>
</div>
<div class="col-sm-1"><label>Guest</label><input type="text" readonly="readonly" id="first_name" name="first_name" class="form-control" value=<?php echo $_POST['first_name']; ?> ></div>
<div class="col-sm-1"><label>Name</label><input type="text" readonly="readonly" id="last_name" name="last_name" class="form-control" value=<?php echo $_POST['last_name']; ?> ></div>
</div>
<div class="col-sm-3">
<button type="submit" class="btn btn-info pull-left">Add It</button>
</div>
</div>
</form>
<hr>
</div>
<div class="container">
<h2>Available Properties</h2>
<div class="table-responsive">
<table class="table table-condensed">
<tr>
<th>Property ID</th>
<th>Description</th>
<th>Cost Per Night</th>
<th>Type of Property</th>
<th>Street Address</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>Host</th>
</tr>
<?php
if(!($query = $mysqli->prepare("SELECT prop_id, description, daily_cost, pt.name AS type, st_address AS address, city, state, zip, h.fname AS host
FROM properties p
INNER JOIN property_type pt ON p.type_id= pt.type_id
INNER JOIN hosts h ON p.host_id = h.host_id
ORDER BY prop_id;"))){
echo "Prepare failed: " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
if(!($query->execute())){
echo "Execute failed: " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
if(!($query->bind_result($prop_id, $description, $daily_cost, $type, $address, $city, $state, $zip, $host))){
"Bind failed: " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
while ($query->fetch()){
echo "<tr>\n<td>" . $prop_id . "\n</td>\n<td>" . $description . "\n</td>\n<td>" . $daily_cost . "\n</td>\n<td>" . $type . "\n</td>\n<td>" . $address . "\n</td>\n<td>" . $city . "\n</td>\n<td>" . $state . "\n</td>\n<td>" . $zip . "\n</td>\n<td>" . $host . "\n</td>\n</tr>";
}
$query->close();
?>
</table>
</div>
</div>
</html>