简体   繁体   English

每次我在我的Android应用程序的http post的帮助下插入一行表,插入两行

[英]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.

相关问题 Android 每次打开我的应用程序时都会触发工作管理器 - Android Work manager get triggered everytime I open my app 我如何从我的网页添加到我的Android应用程序,而又不每次更新apk? - how can i add from my webpage to my android app with out updating the apk everytime? Android Room - 获取新插入行表单的 id @Insert - Android Room - Get the id of new inserted row form @Insert Android从(HTTP)POST到GET - Android from (HTTP) POST to GET 我已经从我的jsp服务器中的android应用收到了HTTP POST,如何将数据传递到Javascript函数中 - I've received an HTTP POST from an android app in my jsp server, how do I pass that data into a Javascript function 如何将表中的所有行获取到android应用 - How to get all rows from a table to an android app 我想通过 whatsapp 从我的应用程序发送音频文件,但每次出现异常时。 我做错了什么? - I want to sent an audio file from my app via whatsapp but everytime I get an exception. What did I do wrong? 从我的应用发布,获取响应,并在Android默认浏览器中显示? - POST from my app, get the respone, and show it in the Android default browser? 如何从sqlite,android获取插入行的详细信息 - How to get details of the inserted row from sqlite, android 如何从Android应用程序中删除Facebook帖子? - How can I delete a Facebook post from my Android app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM