php未接收到NameValuePair变量
我正试图将我的android项目中的一些数据发送到php脚本,以便存储在外部数据库中。以下是我发送数据的方法:php未接收到NameValuePair变量,php,android,post,Php,Android,Post,我正试图将我的android项目中的一些数据发送到php脚本,以便存储在外部数据库中。以下是我发送数据的方法: public void execute(String inComment, LatLng inLatLng) { double lat = inLatLng.latitude; double lng = inLatLng.longitude; Log.d("general", Double.toString(lat)); L
public void execute(String inComment, LatLng inLatLng)
{
double lat = inLatLng.latitude;
double lng = inLatLng.longitude;
Log.d("general", Double.toString(lat));
Log.d("general", Double.toString(lng));
Log.d("general", inComment);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("comment", inComment));
nameValuePairs.add(new BasicNameValuePair("lat", Double.toString(lat)));
nameValuePairs.add(new BasicNameValuePair("lng", Double.toString(lng)));
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url_create_product);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
Log.d("general", "" + response.getStatusLine());
}
catch(Exception e)
{
// TODO: handle exception
Log.e("error", "Error: " + e.toString());
}
}
好像数据没有发布到php脚本。这里可能有什么问题?如何检查PHP变量的值?在实际代码中,我使用if(isset($\u POST['lat'])&&&…{}检查所有POST,但对于测试,我现在使用if(true){}。然后我有一个mysqli_查询($link,“INSERT-INTO-location(
Lat
,Lng
)值(“$Lat”,“$Lng”)”);好的,我解决了这个问题,问题是脚本的URL使用了指向php脚本所在IP的域名,而不是使用IP:PORT。这可能与正在使用的端口有关??
<?php
// location data
$lat = $_POST['lat'];
$lng = $_POST['lng'];
// comment data
$comment = $_POST['comment'];
?>
PHP Notice: Undefined index: lat
PHP Notice: Undefined index: lng
PHP Notice: Undefined index: comment