我一直试图通过youtube上的一些教程将数据从我的应用程序发送到我的本地数据库。程序运行没有错误但是当我尝试将数据发送到我的数据库时没有任何反应。 我必须做一些非常愚蠢的事情,我很不幸,我没有PHP的经验,也无法解决它。这就是我试图使用的代码。
ServerConnection方法
private void serverConnection() {
.
.
.
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("Lat",lat));
nameValuePairs.add(new BasicNameValuePair("Long",log));
nameValuePairs.add(new BasicNameValuePair("Number",svdNum));
try{
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://10.0.2.2/tech/serverConnection.php");
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}
catch(ClientProtocolException e){
Log.e("ClientProtocol", "Log_tag");
e.printStackTrace();
}
catch(IOException e){
Log.e("Log_tag", "IOException");
e.printStackTrace();
}
serverConnection.php
<?php
$conn = mysql_connect(localhost, 'root', '');
mysql_select_db('finalyearproject');
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$Number=$_POST['Number'];
$Latitude=$_POST['Lat'];
$Latitude=$_POST['Long'];
$sql = "INSERT INTO app_backup(Number,Latitude, Longitude) VALUES('$Number', '$Latitude', '$Longitude')";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
?>
提前感谢您的帮助! 我已经编辑了我的PHP代码,它似乎手动工作正常但是当试图从模拟器发送数据没有任何反应。
当我尝试将数据发送到数据库时logcat
04-03 06:11:40.908:W / Trace(868):来自nativeGetEnabledTags的意外值:0 04-03 06:11:59.691:D / ExchangeService(563):从电子邮件app收到deviceId:null 04-03 06:11:59.691:D / ExchangeService(563):!!! deviceId未知;停止自我并重试 04-03 06:12:00.123:W / Trace(277):来自nativeGetEnabledTags的意外值:0 。 。 。 04-03 06:12:04.830:W / Trace(563):来自nativeGetEnabledTags的意外值:0 04-03 06:12:04.859:W / Trace(563):来自nativeGetEnabledTags的意外值:0 04-03 06:12:04.859:D / ExchangeService(563):!!! EAS ExchangeService,onStartCommand,startingUp = false,running = false 04-03 06:12:04.911:W / Trace(563):来自nativeGetEnabledTags的意外值:0 04-03 06:12:04.911:W / Trace(563):来自nativeGetEnabledTags的意外值:0 04-03 06:12:04.911:D / ExchangeService(563):!!! EAS ExchangeService,onStartCommand,startingUp = true,running = false 04-03 06:12:04.989:D / dalvikvm(277):GREF已增加到601 04-03 06:12:04.989:W / ActivityManager(277):无法启动服务Intent {act = com.android.email.ACCOUNT_INTENT} U = 0:未找到 04-03 06:12:05.110:W / Trace(563):来自nativeGetEnabledTags的意外值:0 04-03 06:12:05.208:D / ExchangeService(563):!!!未找到电子邮件申请;阻止自己 04-03 06:12:05.269:W / Trace(563):来自nativeGetEnabledTags的意外值:0 04-03 06:12:05.299:W / Trace(563):来自nativeGetEnabledTags的意外值:0 04-03 06:12:05.381:E / ActivityThread(563):服务com.android.exchange.ExchangeService泄漏了最初绑定的ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cff480 04-03 06:12:05.381:E / ActivityThread(563):android.app.ServiceConnectionLeaked:服务com.android.exchange.ExchangeService泄漏了最初绑定的ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cff480这里 04-03 06:12:05.381:E / ActivityThread(563):在android.app.LoadedApk $ ServiceDispatcher。(LoadedApk.java:969) 04-03 06:12:05.381:E / ActivityThread(563):在android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863) 04-03 06:12:05.381:E / ActivityThread(563):在android.app.ContextImpl.bindService(ContextImpl.java:1418) 04-03 06:12:05.381:E / ActivityThread(563):在android.app.ContextImpl.bindService(ContextImpl.java:1407) 04-03 06:12:05.381:E / ActivityThread(563):在android.content.ContextWrapper.bindService(ContextWrapper.java:473)