-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinsert.php
30 lines (30 loc) · 943 Bytes
/
insert.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
<!DOCTYPE html>
<html>
<head></head>
<body>
<?php
$vehicle_id = $_POST['vehicle_id'];
$date = date( "y-m-d", intval( $_POST['time'] ) / 1000 );
$time = date( "H:i:s", intval( $_POST['time'] ) / 1000 );
$speed = $_POST['speed'];
$lat = $_POST['lat'];
$lon = $_POST['lon'];
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO gps_data (`vehicle_id`, `date`, `time`, `speed`, `latitude`, `longitud`)
VALUES ( {$vehicle_id}, '{$date}', '{$time}', {$speed}, {$lat}, {$lon} )";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo $vehicle_id . "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
</body>
</html>