-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinsert.php
43 lines (38 loc) · 1.32 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
include_once 'config.php';
try {
//Connect to the database.
$dbh = new PDO('mysql:dbname='.$dbname.';host='.$host.';port='.$port, $user, $pass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//Check if the url has the correct parameters
if (isset($_GET["id"]) && isset($_GET["pass"]) && isset($_GET["when"]) && isset($_GET["lon"]) && isset($_GET["lat"])){
$id = $_GET["id"];
$pass = $_GET["pass"];
$when = $_GET["when"];
$lon = $_GET["lon"];
$lat = $_GET["lat"];
$stmt = $dbh->prepare("SELECT * FROM `bus` WHERE `id`=:id AND `pass`=:pass");
$stmt->bindParam(':id', $id);
$stmt->bindParam(':pass', $pass);
$stmt->execute();
//If at least one row has been returned, then the id and the pass are correct.
if($stmt->fetch()) {
//Insert the lon and lat.
$stmt = $dbh->prepare("INSERT INTO `position` (`id`, `when`, `lon`, `lat`) VALUES (:id, :when, :lon, :lat)");
$stmt->bindParam(':id', $id);
$stmt->bindParam(':when', $when);
$stmt->bindParam(':lon', $lon);
$stmt->bindParam(':lat', $lat);
$stmt->execute();
} else {
echo "Wrong id or pass.";
}
} else {
echo "Error in url parameters.";
}
} catch (PDOException $e) {
echo 'Error in sql: ' . $e->getMessage();
}
//Close connection.
$dbh = null;
?>