安卓部分
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代码: -
<?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);
?>
每次我运行它时,都会将具有相同值的两行插入到 mc_log 表中。mc_log 表还有两列 i) id 是主键和 auto_increamented ii) time 是默认的 systime。