我非常接近解决phpMyAdmin连接,但仍然没有发生任何事情,没有错误,没有冻结。这有什么不对?或者也许在我的PHP代码中?
final String suma = Float.valueOf(zam.getSuma()).toString();
ib_wyslij.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new MyAsyncTask().execute(suma);
}
});
private class MyAsyncTask extends AsyncTask<String, Integer, Double> {
@Override
protected Double doInBackground(String... params) {
// TODO Auto-generated method stub
postData(params[0]);
return null;
}
protected void onPostExecute(Double result) {
Toast.makeText(getApplicationContext(), "command sent",
Toast.LENGTH_LONG).show();
}
public void postData(String valueIWantToSend) {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.kuba.ro/exeConn.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("Zam_suma",
valueIWantToSend));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
}
catch (ClientProtocolException e) {
// TODO Auto-generated catch block
}
catch (IOException e) {
// TODO Auto-generated catch block
}
}
}
我的PHP文件的一部分:
$Zam_suma = $_POST['Zam_suma'];
mysql_query("INSERT INTO Zamowienie(Zam_suma) VALUES($Zam_suma)");
答案 0 :(得分:1)
你的asynctask中你需要什么样的参数Integer和Double?如果您只需要asynctask来发布字符串,则可以将Void
用于其他参数:
private class MyAsyncTask extends AsyncTask<String, Void, Void>
将@Override
注释添加到onPostExecute()
以覆盖该方法(请参阅Arjan的回答)。
在catch块中调用e.printStackTrace()
以查看错误发生的时间,地点和原因。
答案 1 :(得分:-1)