我是Android開發人員的初學者。我想將一個php文件連接到android應用程序。我的PHP代碼是與android項目的php連接
<?php
$con = mysqli_connect("localhost", "root", "", "invoice_db");
if(mysqli_connect_errno($con)) {
echo "Failed to connect";
}
$response["sucess"]=0;
$invoiceid = $_POST['invc'];
$response = array();
$sql = "SELECT sl_no from invoice_table where invoice_id='$invoiceid'";
$result = mysqli_query($con,$sql);
if(!empty($result)) {
$row = mysqli_fetch_array($result);
$data = $row[0];
$response["sucess"] = 1;
}
mysqli_close($con);
?>
這裏INVC'是HttpRequest都有,
JSONObject json = jsonParser.makeHttpRequest(url_check_user, "POST", params);
而且我JSONParser頁面包含,
if (method == "POST") {
// request method is POST
// defaultHttpClient
System.out.println("Inside json parser POST condition");
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
System.out.println("Inside json parser POST condition" + params);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
Log.d("From httpentity", httpEntity.toString());
System.out.println("ppppppppppppphhhhhhhhhhhhhhhhhhhhppppppppppp");
is = httpEntity.getContent();
}
現在我要檢查,參數是否傳遞給php頁面或不。所以我想安慰/登錄貓$invoiceid
。 Eclipse IDE中怎麼可能?
你可能會改變的另一件事是'method =='POST''到'method.equals(「POST」)'。 –
這是真的,在Java中,您必須使用'.equals(...)'方法比較字符串,因爲'=='運算符比較實例(即引用) – user2340612