簡體   English   中英

帶有php web服務的android

[英]android with php web service

我正在使用php開發用於網絡服務的android應用。 在我的應用程序中,我已經在php文件中插入,更新,刪除和搜索查詢,並保存到www根目錄,然后我將php文件稱為android應用程序。 搜索功能運行良好,但刪除功能不起作用。 我已經附上了php文件,android代碼和Error也。任何人都可以幫助我嗎?

 **filename** (deletedetail.php)

<?php
include "config.php";

$id = $_POST['id'];

$sql1="delete from detail where id ='$id'";

$result=mysql_query($sql1);

 if($result)
{
  echo"OK";
}
  else
{
  echo "Error";

}

?>






**android CODE**

public String deleteDetail(int id) { 
        try {

            httpclient = new DefaultHttpClient(); 
            httppost = new HttpPost(
                    "http://10.0.2.2/dreamhotel/deletedetail.php"); // change this to your URL.....
            nameValuePairs = new ArrayList<NameValuePair>(1);
            nameValuePairs.add(new BasicNameValuePair("id",Integer.toString(id)));
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            response = httpclient.execute(httppost,responseHandler);       


        } catch (Exception e) {  
            System.out.println(e.getMessage());

        }
        return response;  
    }

Error in Android

at com.android.internal.os.LoggingPrintStream.println(LoggingPrintStream.java:298)

請使用HTTP GET方法而不是HTTP POST,並且對於HTTP GET方法,URL應該是。

http://10.0.2.2/dreamhotel/deletedetail.php?id=1

並進行一些chnage服務器端:用戶服務器端$ _GET或$ _REQUEST而不是$ _POST。

參見下文,我編輯了您的代碼。

<?php
include "config.php";

//$id = $_POST['id'];
$id = $_GET['id'];

$sql1="delete from detail where id ='$id'";

$result=mysql_query($sql1);

 if($result)
{
  echo"OK";
}
  else
{
  echo "Error";

}

?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM