-
Notifications
You must be signed in to change notification settings - Fork 0
/
add.php
220 lines (215 loc) · 6.42 KB
/
add.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
<?php
session_start();
include("pdo.inc.php");
#CONTROL
if ( isset($_POST['date']) && isset($_POST['time']) && isset($_POST['temp'])
&& isset($_POST['pressure']) && isset($_POST['humidity']) && isset($_POST['wind_speed'])
&& isset($_POST['wind_dir']) || isset($_POST['condit']) || isset($_POST['status']))
{
if (empty($_POST['date']) || empty($_POST['time'])
|| empty($_POST['pressure']) || empty($_POST['humidity']) || empty($_POST['wind_speed'])
|| empty($_POST['wind_dir']) || empty($_POST['condit']) || empty($_POST['status']))
{
$_SESSION["error"] = "All rows are required";
header("Location: add.php");
return;
}
elseif (!is_numeric($_POST['time']) || !is_numeric($_POST['temp']) ){
$_SESSION["error"] = "Time and temperature must be numeric";
header("Location: add.php");
return;
}
else{
$_SESSION["date"] = $_POST["date"];
$_SESSION["time"] = $_POST["time"];
$_SESSION["temp"] = $_POST["temp"];
$_SESSION["pressure"] = $_POST["pressure"];
$_SESSION["humidity"] = $_POST["humidity"];
$_SESSION["wind_speed"] = $_POST["wind_speed"];
$_SESSION["wind_dir"] = $_POST["wind_dir"];
$_SESSION["condit"] = $_POST["condit"];
$_SESSION["status"] = $_POST["status"];
$stmt = $pdo->prepare('INSERT INTO mehd1brahimov_weather.weather_all
(date, time, temp, pressure, humidity, wind_speed, wind_dir, condit, status)
VALUES ( :dt, :ti, :tp, :pr, :hm, :ws, :wd, :cd, :st)');
$stmt->execute(array(
':dt' => htmlentities($_SESSION["date"]),
':ti' => htmlentities($_SESSION["time"]),
':tp' => htmlentities($_SESSION["temp"]),
':pr' => htmlentities($_SESSION["pressure"]),
':hm' => htmlentities($_SESSION["humidity"]),
':ws' => htmlentities($_SESSION["wind_speed"]),
':wd' => htmlentities($_SESSION["wind_dir"]),
':cd' => htmlentities($_SESSION["condit"]),
':st' => htmlentities($_SESSION["status"]))
);
$_SESSION["success"] = "Record inserted";
#$stmt = $pdo->query("SELECT make, year, mileage FROM autos");
#$_SESSION["rows"] = $stmt->fetchAll(PDO::FETCH_ASSOC);
header("Location: index.php");
return;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Add new records</title>
<style>
* {
box-sizing: border-box;
}
input[type=text], input[type=date],input[type=number], select, textarea {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
resize: none;
}
label {
display: inline-block;
}
.abc{
display:inline-block;
text-align: right;
align-items: right;
float: right;
padding-top: 5px;
}
input[type=submit] {
border: 2px solid black;
color: black;
padding: 12px 20px;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #7bda75;
}
.link{
padding: 12px 20px;
border: 2px solid black;
color: black;
border-radius: 5px;
cursor: pointer;
text-decoration:none;
}
.link:hover{
background-color: #da757b;
}
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
.col-25 {
float: left;
width: 25%;
margin-top: 6px;
}
.col-75 {
float: left;
width: 75%;
margin-top: 6px;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Responsive layout - when the screen is less than 600px wide, make the two columns stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
.col-25, .col-75, input[type=submit] {
width: 100%;
margin-top: 0;
}
}
</style>
</head>
<body>
<div class="container">
<?php
if ( isset($_SESSION["error"]) ) {
echo('<p style="color:red">'.$_SESSION["error"]."</p>\n");
unset($_SESSION["error"]);
}
?>
<form method="post">
<div class="row">
<div class="col-25">
<label for="date">Date:</label>
</div>
<div class="col-75">
<input type="date" name="date"/>
</div>
<div class="col-25">
<label for="time">Time:</label>
</div>
<div class="col-75">
<input type="number" name="time"/>
</div>
<div class="col-25">
<label for="temp">Temperature:</label>
</div>
<div class="col-75">
<input type="number" name="temp"/>
</div>
<div class="col-25">
<label for="pressure">Pressure:</label>
</div>
<div class="col-75">
<input type="text" name="pressure"/>
</div>
<div class="col-25">
<label for="humidity">Humidity:</label>
</div>
<div class="col-75">
<input type="text" name="humidity"/>
</div>
<div class="col-25">
<label for="wind_speed">Wind Speed:</label>
</div>
<div class="col-75">
<input type="text" name="wind_speed"/>
</div>
<div class="col-25">
<label for="wind_dir">Wind Direction:</label>
</div>
<div class="col-75">
<input type="text" name="wind_dir"/>
</div>
<div class="col-25">
<label for="condit">Condition:</label>
</div>
<div class="col-75">
<select id="condit" name="condit">
<option value="" disabled selected>Choose option</option>
<option value="Sunny">Sunny</option>
<option value="Cloudy">Cloudy</option>
<option value="Rainy">Rainy</option>
<option value="Snowy">Snowy</option>
<option value="Windy">Windy</option>
</select>
</div>
<div class="col-25">
<label for="status">Status:</label>
</div>
<div class="col-75">
<select id="status" name="status">
<option value="" disabled selected>Choose option</option>
<option value="Severe">Severe</option>
<option value="Humid">Humid</option>
<option value="Calm">Calm</option>
<option value="Clear">Clear</option>
</select>
</div>
<div class=abc>
<input type="submit" name='add' value="Add">
<a class="link" href="index.php">Cancel</a>
</div>
</form>
</div>
</div>
</body>
</html>