我是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