douyi9787 2017-04-07 19:53
浏览 45
已采纳

使用PHP从服务器获取经度和纬度

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));
}
  • 写回答

2条回答 默认 最新

  • duandushang5148 2017-04-07 19:56
    关注

    $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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀