0
我有一個錯誤,我似乎無法弄清楚爲什麼。我試圖發佈數據到一個PHP文件,並陷入一個捕獲錯誤。我收到的敬酒是「數據未發送」,但我收到了「數據已準備好」之前敬酒。任何人都可以看看並幫助我確定我的問題是什麼?使用android發佈數據時發生錯誤
Android的方法:
public void insertToDB(String data){
try {
HttpClient client=new DefaultHttpClient();
HttpPost getMethod=new HttpPost("http://shawnc.webuda.com/upload.php");
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("RPM",data));
getMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
String toastText = "Data was prepared";
Toast.makeText(getApplicationContext(), toastText, Toast.LENGTH_SHORT).show();
try {
client.execute(getMethod);
toastText = "Data has been sent: " + data;
Toast.makeText(getApplicationContext(), toastText, Toast.LENGTH_SHORT).show();
}catch(Exception e){
toastText = "Data was not sent";
Toast.makeText(getApplicationContext(), toastText, Toast.LENGTH_SHORT).show();
}
}catch(Exception e){
String toastText = "Data could not be prepared";
Toast.makeText(getApplicationContext(), toastText, Toast.LENGTH_SHORT).show();
}
}
和我的PHP文件:
<?
$hostname_host ="MYSQLxxxxx.Smarterasp.net";
$database_host ="db_xxxxx_db";
$username_host ="9xxxxx_db";
$password_host ="password";
$server= mysql_connect($hostname_localhost,$username_localhost,$password_localhost)
or
trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db("db_xxxxx_db");
$sql=mysql_query("INSERT INTO driverdata (RPM)VALUES('".$_REQUEST['RPM']."')");
$r=mysql_query($sql);
if(!$r)
echo "Error in query: ".mysql_error();
mysql_close();
?>
檢查異常中的錯誤消息。最有可能包含有助於您解決問題的有用信息。這可能是網絡問題,服務器配置,誰知道。看看例外。異常中的堆棧跟蹤和消息是什麼? – 2014-10-08 04:27:06
我怎樣才能看到堆棧跟蹤。我從手機上運行它,因爲它連接到我車裏的obdII傳感器,所以我不能使用模擬器? – Shawn 2014-10-08 04:28:44
它可能是這行'$ server = mysql_connect($ hostname_localhost,$ username_localhost,$ password_localhost) 或 trigger_error(mysql_error(),E_USER_ERROR);' - 它可能需要一個'if/else' - 嘗試'if server = mysql_connect($ hostname_localhost,$ username_localhost,$ password_localhost)) else {trigger_error(mysql_error(),E_USER_ERROR);}' - 請參閱http://php.net/manual/en/function.trigger-error.php再舉幾個例子。 – 2014-10-08 04:33:24