[英]Android PHP Mysql get Data by params
I'm making android app with communication to PHP MySQL there is PHP files 我正在与android通信的android应用程序MySQL MySQL有PHP文件
create_order.php
get_all_orders.php
get_order_status.php
create_order.php works get_all_orders.php also but example in browser I'm typing get_order_status.php?oid=102 it gives me response but it contains an error {"success":0,"message":"Required field(s) is missing get status"}
when trying it from android by POST method create_order.php也可以使用get_all_orders.php,但是在浏览器中的示例中,我输入的是get_order_status.php?oid = 102,它给了我响应,但其中包含错误
{"success":0,"message":"Required field(s) is missing get status"}
当通过POST方法从android尝试{"success":0,"message":"Required field(s) is missing get status"}
时
RequestQueue queue = MyVolley.getRequestQueue();
String num1 = "1";
if (num1 != null && !num1.equals("")) {
String uri = String
.format("http://192.168.0.101/android_connect/get_order_status.php?param1=%1$s",
num1);
StringRequest myReq = new StringRequest(Request.Method.GET,
uri,
createMyReqSuccessListener(),
createMyReqErrorListener());
queue.add(myReq);
}
get_order_status.php get_order_status.php
/*
* Following code will get single product details
* A product is identified by product id (pid)
*/
// array for JSON response
$response = array();
// include db connect class
//require_once __DIR__ . '/db_connect.php';
// connecting to db
//$db = new DB_CONNECT();
// check for post data
//echo("post data - ".$_GET['oid']);
if (isset($_GET['oid'])) {
$pid = $_GET['oid'];
// get a order from orders table
$mysqli = new mysqli('localhost','root','rootpass','testdb');
$result = mysqli_fetch_array($mysqli->query("SELECT * FROM orders WHERE oid = $pid"));
//echo($result["status"]);
if (count($result)>0) {
// check for empty result
$order = array();
$order ["status"] = $result["status"];
// success
$response["success"] = 1;
// user node
$response["order"] = array();
array_push($response["order"], $order);
// echoing JSON response
echo json_encode($response);
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No order found";
// echo no users JSON
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing get status";
// echoing JSON response
echo json_encode($response);
}
?>
change param1
to oid
in this line (android code) 在此行将
param1
更改为oid
(Android代码)
String uri = String.format("http://192.168.0.101/android_connect/get_order_status.php?param1=%1$s",num1);
should be like this: 应该是这样的:
String uri = String.format("http://192.168.0.101/android_connect/get_order_status.php?oid=%1$s",num1);
as in your PHP file you are reading parameter named oid
就像在您的PHP文件中一样,您正在读取名为
oid
参数
$pid = $_GET['oid'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.