-
Notifications
You must be signed in to change notification settings - Fork 5
/
submit.php
70 lines (53 loc) · 1.75 KB
/
submit.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
<?php
include('functions.php');
date_default_timezone_set('Europe/London');
if( $_POST ){
$origin = $_POST['txt_origin'];
$destination = $_POST['txt_destination'];
$date = $_POST['txt_date'];
$userId = $_POST['txt_userid'];
$departureTime = $_POST['txt_departure'];
$departEpoch = strtotime($date . " " . $departureTime);
$request_url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=" . urlencode($origin) . "&destinations=" . urlencode($destination) . "&mode=transit&departure_time=" . $departEpoch . "&key=XXXXXXXXXXXXXXXXXX";
$details = json_decode(file_get_contents($request_url));
$distance = $details->rows[0]->elements[0]->distance->value;
$duration = $details->rows[0]->elements[0]->duration->value;
$response = $details->status;
if($response != "OK") {
exit;
}
connectDB();
$qq = "INSERT into data (userID,origin,destination,distance,duration,date) VALUES ($userId,'" . $origin . "','" . $destination . "',$distance,$duration,'" . $date . "')";
$result = mysql_query($qq);
?>
<table class="table table-striped" border="0">
<tr>
<td colspan="2">
<div class="alert alert-info">
<strong>Success</strong>, Journey Submitted Successfully...
</div>
</td>
</tr>
<tr>
<td>Origin</td>
<td><?php echo $origin ?></td>
</tr>
<tr>
<td>Destination</td>
<td><?php echo $destination ?></td>
</tr>
<tr>
<td>Distance</td>
<td><?php echo ceil($distance/1000) . " Kms"; ?></td>
</tr>
<tr>
<td>Duration</td>
<td><?php echo secondsToTime($duration); ?></td>
</tr>
<tr>
<td>Date</td>
<td><?php echo $date; ?></td>
</tr>
</table>
<?php
}