Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从android手机在php服务器上发布gps坐标_Php_Android_Post_Gps - Fatal编程技术网

从android手机在php服务器上发布gps坐标

从android手机在php服务器上发布gps坐标,php,android,post,gps,Php,Android,Post,Gps,我正在尝试的是获取我的当前位置(坐标),并将这些坐标发布到服务器上。我用WAMP做了一个服务器。我已经用java编写了php代码和代码,但在帖子中显示了错误。请告诉我它是否正确,或者我是否可以修改它 PHP代码 <?php echo 'Hello, world!'; $json = $_GET['jsonpost'];//get the post you sent... $data = json_decode($json); //decode the json formatted stri

我正在尝试的是获取我的当前位置(坐标),并将这些坐标发布到服务器上。我用WAMP做了一个服务器。我已经用java编写了php代码和代码,但在帖子中显示了错误。请告诉我它是否正确,或者我是否可以修改它

PHP代码

<?php
echo 'Hello, world!';
$json = $_GET['jsonpost'];//get the post you sent...
$data = json_decode($json); //decode the json formatted string...
print_r($data);
$id = $data->id;
$devid = $data->devid;
$latitude = $data->latitude;
$longitude = $data->longitude;
$service = $data->service;
$con = mysql_connect("","","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("a5234826_ul", $con);
$devid = $_POST['devid']; 
$latitude = $_POST['latitude'];
$longitude = $_POST['longitude'];
echo "devid" +$devid;
echo "latitude" + $latitude;
echo "longitude" + $longitude; 
$sql = "INSERT INTO  `a5234826_ul`.`locations` (
`id` ,
`devid` ,
`latitude` ,
`longitude` ,
`service`
)
VALUES (
NULL ,  '$devid',  '$latitude',  '$longitude', '$service'  
)";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
mysql_close($con);
echo json_encode($variable);

我在这里看到的主要问题是,您正在谈论
POST
,但在您的android
LocationService
中,您正在创建一个
HttpGet
对象:

HttpGet httppost = new HttpGet("http://.../serverFile.php");
然后不知从何处将
httpost
变量用作
post

post.setHeader("json",json.toString());
post.getParams().setParameter("jsonpost",postjson);
在PHP中,我不确定您想通过以下方式实现什么:

$_SERVER['HTTP_JSON'];
因为我肯定没有这样的索引。取而代之的是打电话

$_POST['jsonpost']; // <-- that is the parameter name from Your JAVA code...

$\u POST['jsonpost'];//我没有从那里复制粘贴它。。我到底该怎么办。。你能帮我一下吗。。。拜托,嘿,我编辑了一些东西。。。一切正常。。。但是坐标和设备id没有被发布……好吧,那么试试谷歌这个词:安卓发布数据。首先使用google,当找不到解决方案时,在这里询问……我知道这篇老文章,但是有人应该注意到上面的PHP代码容易受到SQL注入的攻击,这是一个相当大的安全问题。请参阅单词POST上的获取错误…@shadyyx请查看编辑的部分。。。?我不能运行你的android代码,所以我不能说它是否可以。。。你的错误信息到底是什么?我试过了…代码。。但应用程序是强制关闭的…编辑了我的答案,请阅读,思考你在做什么,并尝试使用。。。
$_POST['jsonpost']; // <-- that is the parameter name from Your JAVA code...
$_GET['jsonpost']; // <-- that is the parameter name from Your JAVA code...
<?php
echo 'Hello, world!';

$json = $_GET['jsonpost']; // get the json you sent through GET...
$data = json_decode($json); // decode the json formatted string...

print_r($data); // print out the $data variable to see whether everything is OK...

$devid = $data->devid;
$longitude = $data->longitude;
$latitude = $data->latitude;

$con = mysql_connect("","","") or die('Could not connect: ' . mysql_error());    
mysql_select_db("a5234826_ul", $con);

echo "devid" +$devid;
echo "latitude" + $latitude;
echo "longitude" + $longitude; 

$sql = "INSERT INTO  `a5234826_ul`.`locations` (
    `devid`,
    `latitude`,
    `longitude` 
) VALUES (
    '$Devid',
    '$latitude',  
    '$longitude'
);";
if (!mysql_query($sql,$con)) {
    die('Error: ' . mysql_error());
}

mysql_close($con);
echo json_encode($variable);