Reputation: 9
I am trying to build an Android app which queries a server to get the latitude and longitude for the given destination. However there seems to be an error in my PHP code as it shows the following error when I input the address in the web browser.
Notice: Undefined variable: destination in C:\xampp\htdocs\serverfiles\btc.php on line 6
{"result":[{"latitude":null,"longitude":null}]}
This is my btc.php file:
<?php
if($_SERVER['REQUEST_METHOD']=='GET'){
$id = $_GET['destination'];
$con = mysqli_connect("127.0.0.1", "root", "", "bustrack");
$sql = "SELECT * FROM updates WHERE destination='".$destination."'";
$r = mysqli_query($con,$sql);
$res = mysqli_fetch_array($r);
$result = array();
array_push($result,array(
"latitude"=>$res['latitude'],
"longitude"=>$res['longitude'],
)
);
echo json_encode(array("result"=>$result));
}
Upvotes: 0
Views: 164
Reputation: 23493
This issue is that you never assign $destination
a variable:
$id = $_GET['destination'];
$con = mysqli_connect("127.0.0.1", "root", "", "bustrack");
$sql = "SELECT * FROM updates WHERE destination='".$destination."'";
You should do this:
$id = $_GET['destination'];
$con = mysqli_connect("127.0.0.1", "root", "", "bustrack");
$sql = "SELECT * FROM updates WHERE destination='".$id."'";
Upvotes: 0
Reputation: 581
$sql = "SELECT * FROM updates WHERE destination='".$destination."'";
The variable $destination
does not exist. You need to declare it before using it. I believe the variable $id
is what you want, looking to your code.
Upvotes: 1