dtzh131555 2016-05-23 05:54
浏览 43

PHP中的JSON问题

I am trying to create a restAPI to get some details from MySQL for this I have created a PHP file to access them on Android devices.

Here is the PHP file:

<?php

include("db_details.php");

$response = array();

if (isset($_POST['userID'])) 
{
    $userID = $_POST['userID'];
    $grantedvalue = "granted";

    $stmt = mysqli_prepare($bd, "SELECT p.name, p.userURL, a.grantaccuracy FROM loc_details d JOIN loc_profile p ON d.userID = p.userId JOIN loc_friends a on a.userId = d.userId WHERE a.grantstatus = ? and a.grantuserID = ?");
    mysqli_stmt_bind_param($stmt, "ss", $grantedvalue,  $userID);
    $checkresult = mysqli_stmt_execute($stmt);
    $result = $stmt->get_result();
    if (!$checkresult) 
    {
       die("Error updating user_details_table: " . mysqli_stmt_error($stmt));

    }
    else
    {              
       echo $result -> num_rows;
       if($result -> num_rows > 0)
       {
            $response["details"] = array();

            while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) 
            {
                // temp user array
                $detail = array();
                $detail["name"] = $row["name"];
                $detail["userURL"] = $row["userURL"];
                $detail["grantaccuracy"] = $row["grantaccuracy"];

                array_push($response["details"], $detail);
            }
             $response["success"] = 1;
         echo json_encode($response);
       } 
          else
          {
            $response["success"] = 0;
            $response["message"] = "Zero Data";

            echo json_encode($response);
          }
    }
}
else
{
    $response["success"] = 300;
    $response["message"] = "issue with getting values";
    echo json_encode($response);
}
?>

I am using AsyncHttpClient Library to access the above php file. The results are not coming up there but when I try to access the php directly on browser something like this:

http://www.thiswillhavemycompanydomain.com/loc/get_user_details.php?userID=2238

The results are getting printed correctly on the browser. So I thought it could be an issue with coding part in android hence I tried using the Chrome Extension (Advance REST CLIENT) to see if I can get the results.. Strangely I am not getting results even there. I am always getting the else part of if (isset($_POST['userID'])) from the php code.

Not sure what could be wrong here as I can view all the data on my browser directly but not on ARC or my android APP?

Can somebody help me fix this as I don't know where could be the problem?

Thanks!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line