Repository navigation
Expand file tree
/
Copy pathgetReqDB.php
More file actions
executable file
·62 lines (49 loc) · 1.49 KB
/
Copy pathgetReqDB.php
File metadata and controls
executable file
·62 lines (49 loc) · 1.49 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
<?php
//echo "Request Processed";
ini_set('display_errors', 'On');
//get request type
$result= $_GET['InputType'];
//login into database
$mysqli = new mysqli("oniddb.cws.oregonstate.edu","hallbry-db","HnY9rGK4KVocyQJk","hallbry-db");
//Turn on error reporting
if(!$mysqli || $mysqli->connect_errno){
echo "Connection error " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
if ($result === "getLatLng"){
if(!($stmt = $mysqli->prepare("SELECT latitude, longitude FROM Individual WHERE id = ?"))){
echo "Prepare failed: " . $stmt->errno . " " . $stmt->error;
}
$id = $_GET['id'];
if(!($stmt->bind_param("i", $id))){
echo "Bind failed: " . $stmt->errno . " " . $stmt->error;
}
//failed to execute
if(!$stmt->execute()){
echo "Execute failed: " . $stmt->errno . " " . $stmt->error;
}
//prepare results
if(!$stmt->store_result()){
echo "Bind failed: " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
// If there is latitude and longitude, print them
if($stmt->num_rows === 1){
if (!$stmt->bind_result($latitude, $longitude)){
echo "Bind failed: ".$stmt->errno." ".$stmt->error;
}
else{
$stmt->fetch();
$json_array = array(
'latitude' => $latitude,
'longitude' => $longitude
);
echo json_encode($json_array);
}
}
else echo "could not get latitude and longitude";
$stmt->close();
}
// Otherwise, it didn't catch any of the input types
else{
echo "error";
}
?>