[英]everytime i insert a row into a table with the help of http post from my android app, two rows get inserted
Android part Android部分
final ProgressDialog p = new ProgressDialog(arg0.getContext()).show(arg0.getContext(),"Waiting for Server", "Accessing Server");
Thread thread = new Thread()
{
@Override
public void run() {
try{
httpclient=new DefaultHttpClient();
httppost= new HttpPost("http://www.ng.in/m/z.php");
nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("z_101","3"));
nameValuePairs.add(new BasicNameValuePair("uname",info));
nameValuePairs.add(new BasicNameValuePair("bill",""+bill));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//Execute HTTP Post Request
response=httpclient.execute(httppost);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
final String response = httpclient.execute(httppost, responseHandler);
System.out.println("Response : " + response);
runOnUiThread(new Runnable() {
public void run() {
p.dismiss();
pay.append(response);
}
});
}catch(Exception e){
e.printStackTrace();
}
}
};
thread.start();
Php Code:- PHP代码: -
<?php
require "connect.inc.php";
$uname=$_POST['uname'];
$bill=(int)$_POST['bill'];
$z_101=(int)$_POST['z_101'];
$rest="z";
$query1="insert into mc_log (uname,rname,bill) values ('$uname','$rest','$bill')";
$result1=mysql_query($query1);
?>
Everytime i run it two rows with the same values are getting inserted into the mc_log table. 每次运行它时,两行具有相同的值都会插入到mc_log表中。 The mc_log table has two more columns i) id which is primary key and auto_increamented ii) time which is by default systime.
mc_log表还有两列i)id是主键,auto_increamented ii)时间,默认为systime。
This code looks doubled: 此代码看起来加倍:
//Execute HTTP Post Request
response=httpclient.execute(httppost);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
fnal String response = httpclient.execute(httppost, responseHandler);
You are calling execute()
two times, that is the problem... 你正在调用
execute()
两次,这就是问题......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.