duandan4680 2016-04-17 10:21
浏览 68

Android PHP Mysql通过params获取数据

I'm making android app with communication to PHP MySQL there is PHP files

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

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

/*
 * 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);
}
?>  
  • 写回答

1条回答 默认 最新

  • douhui8025 2016-04-17 12:28
    关注

    change param1 to oid in this line (android code)

    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

    $pid = $_GET['oid'];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?