我试图将我的android项目中的一些数据发送到php脚本以存储在外部数据库中。这就是我发送数据的方法如下:
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());
}
}
记录的结果是:
13.0
12.0
测试评论
HTTP / 1.1 200确定
我的php脚本看起来像这样:
<?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
好像数据没有发布到php脚本。这可能有什么问题?