-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest.php
More file actions
179 lines (152 loc) · 4.31 KB
/
request.php
File metadata and controls
179 lines (152 loc) · 4.31 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
178
179
<?php
session_start();
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
if (!isset($_SESSION["email"])) {
header("Location: index.php");
exit();
}
$email = $_SESSION["email"];
$conn = mysqli_connect("localhost", "root", "", "aqi");
if (!$conn) {
die("Connection failed.");
}
$cities = [];
$sql = "SELECT city FROM info LIMIT 20";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$cities[] = $row['city'];
}
$error = '';
$selected = [];
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['cities'])) {
$selected = $_POST['cities'];
}
$count = count($selected);
if ($count < 1 || $count > 10) {
$error = "Please select between 1 and 10 countries. You selected $count.";
} else {
$_SESSION['selected_cities'] = $selected;
header("Location: showAQI.php");
exit();
}
}
mysqli_close($conn);
?>
<!DOCTYPE html>
<html>
<head>
<title>Select Countries</title>
<style>
body {
font-family: 'Segoe UI', sans-serif;
background: lightblue;
display: flex;
justify-content: center;
align-items: flex-start;
padding-top: 60px;
margin: 0;
min-height: 100vh;
}
.container {
background: white;
padding: 30px 40px;
border-radius: 12px;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
width: 450px;
max-width: 90%;
}
.username {
text-align: right;
font-weight: 600;
color: #007bff;
margin-bottom: 15px;
font-size: 14px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
h2 {
margin-bottom: 25px;
color: #333;
text-align: center;
}
.error {
color: #e60000;
font-weight: bold;
margin-bottom: 15px;
}
.city-list {
display: flex;
flex-direction: column;
gap: 10px;
margin-bottom: 20px;
}
.city-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 8px 12px;
background: #f1f9ff;
border-radius: 6px;
}
.city-item:hover {
background: #e0f0ff;
}
input[type="checkbox"] {
transform: scale(1.3);
accent-color: #007bff;
}
button {
width: 100%;
padding: 12px;
font-size: 16px;
font-weight: bold;
color: white;
background-color: #007bff;
border: none;
border-radius: 6px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
form + form {
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<div class="username">
Username: <?php echo htmlspecialchars($email); ?>
</div>
<h2>Select between 1 and 10 countries</h2>
<?php if ($error != ''): ?>
<div class="error"><?php echo $error; ?></div>
<?php endif; ?>
<form method="post" action="request.php">
<div class="city-list">
<?php foreach ($cities as $city): ?>
<?php $checked = in_array($city, $selected) ? 'checked' : ''; ?>
<div class="city-item">
<span><?php echo htmlspecialchars($city); ?></span>
<input type="checkbox" name="cities[]" value="<?php echo htmlspecialchars($city); ?>" <?php echo $checked; ?>>
</div>
<?php endforeach; ?>
</div>
<button type="submit">Submit</button>
</form>
<form method="post" action="logout.php">
<button type="submit" style="margin-top: 10px; background: #dc3545;">Logout</button>
</form>
</div>
<script>
window.addEventListener("pageshow", function (event) {
if (event.persisted || (performance && performance.navigation.type === 2)) {
window.location.reload();
}
});
</script>
</body>
</html>