-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfavourite.php
244 lines (199 loc) · 6.5 KB
/
favourite.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
236
237
238
239
240
241
242
243
244
<?php
//Reference-https://codewithawa.com/posts/complete-user-registration-system-using-php-and-mysql-database
//Youtube-Tutorial-https://www.youtube.com/watch?v=C--mu07uhQw
//Only the session function taken from the above links
session_start();
if (!isset($_SESSION['username'])) {
$_SESSION['msg'] = "You must log in first";
header('location: login.php');
}
if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION['username']);
header("location: home.php");
}
$res="";
$ves="";
?>
<!DOCTYPE html>
<html>
<head>
<title>Favourites</title>
<link rel="stylesheet" type="text/css" href="styleindex.css">
<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" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<div class="navbar-static-topic" id="top">
<div class="container">
<div class="navbar-brand">
© The Weather Application
</div>
<div class="navbar-brand">
Welcome <strong><?php echo $_SESSION['username']; ?></strong>
</div>
<button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
Menu
</button>
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-right">
<li class="navigation"><a href="index.php"><span>Home</span></a></li>
<li class="navigation">
<a href="#search">
<p>Delete</span></p>
</a>
</l1>
<li class="navigation"><a href="favourite.php?" style="color: blue;">Favourites</a></li>
<li class="navigation"><a href="index.php?logout='1'" style="color: red;">Logout</a></li>
</ul>
</div>
</div>
</div>
<!-- notification message -->
<?php if (isset($_SESSION['success'])) : ?>
<div class="error success">
<h3>
<?php
echo $_SESSION['success'];
unset($_SESSION['success']);
?>
</h3>
</div>
<?php endif ?>
<!-- logged in user information -->
<?php if (isset($_SESSION['username'])) : ?>
<div class="jumbotron">
<div class="container">
<h2>Welcome to the Live Weather Application.</h2>
<p>The website where you can get all the weather information you want, for any city in the world.</p>
</div>
</div>
<br/>
<br/>
<h2 class="text-center">Welcome to the favourites tab, view live weather for your favourite locations below. <h2/>
<hr/>
<div class="container text-center" id="search">
<div class="row">
<div class="col-md-12">
<div class="container">
<h3><b>Delete your favourite locations</b></h3>
<form action="" method="post">
<label id="first">ID</label><br/>
<input type="text" name="id3" placeholder="Enter Id of Location"><br/>
<br/>
<button name="delete">Delete</button>
</form>
<br/>
<hr/>
<h3>
Your favourites
</h3>
<?php
if(!isset($_POST['id3']) || trim($_POST['id3']) == '')
{
echo"";
}
else{
$user = 'root';
$pass = '';
$db = 'favourites';
$conn = new mysqli('localhost', $user, $pass, $db) or die("Unable to connect");//delete
if(isset($_POST['delete']))
{
$sql="DELETE FROM favourites WHERE id='".$_POST["id3"]."'" or die ("this stuffed up");
$result = mysqli_query($conn,$sql);
}
}
?>
<?php
$user = 'root';
$pass = '';
$db = 'favourites';
$conn = new mysqli('localhost', $user, $pass, $db) or die("Unable to connect");
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo " <br> <br>";
$sql = "SELECT * FROM favourites WHERE username='".$_SESSION['username']."'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "Location ID: " . $row["id"] . "<br>" . $row["location"]. "<br>" ;
$loc=$row["location"];
$id= $row["id"];
}
$ves=0;
}
else {
echo "There are no favourites to display.";
$res=1;
}
?>
<hr/>
<?php
if($res > $ves){
echo"";
}
else{
$link1="https://maps.googleapis.com/maps/api/geocode/json?address=";
$link2= $loc;
$link2=str_replace(" ", "", $link2);
$link3="&key=AIzaSyA0W7gxcPBJ3NNN5BH4nVRs-dLVM4zems4";
$url=$link1.$link2.$link3;
$json=file_get_contents($url);
$results = json_decode($json);
$coordinates = $results->results;
$lat = $coordinates[0]->geometry->location->lat;
$long = $coordinates[0]->geometry->location->lng;
$a="http://api.weatherunlocked.com/api/current/";
$b=",";
$c="?app_id=02694b99&app_key=ce8ea19839f35b0e536bc9ea656d8d77";
$xml_string=$a.$lat.$b.$long.$c;
$xml = file_get_contents($xml_string);
$json = json_decode($xml);
echo "Temperature at ".$loc.'<br/>';
echo "Temperature " .$json->temp_c." .C".'<br/>';
echo "Feels like " .$json->feelslike_c ." .C".'<br/> ';
echo "Wind Speed " .$json->windspd_kmh ." Kmph".'<br/> ';
echo "Humidity " .$json->humid_pct ." %".'<br/> '; }?>
</div>
</div>
</div>
</div>
<hr/>
<br/>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="js/bootstrap.js"></script>
<script>
$(function() {
$('a[href*="#"]:not([href="#myCarousel"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
</script>
<?php endif ?>
<div class="footer">
<div class="container">
<footer>
© The Weather Application
<br/>
<a href="#top">Back To Top</a>
</footer>
</div>
</div>
</body>
<!--echo "ID: " . $row["id"] . "<br> Name: " . $row["username"]. "<br>" . " Location: " . $row["location"]. "<br>" ;-->
</html>