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!