I am trying to send userid to server and fetch the data related to the userid in android using Volley connectivity and php script But i am getting Error like :
com.android.volley.ParseError: org.json.JSONException: Value UserId of type java.lang.String cannot be converted to JSONObject
other Error Like :End of Input character 0 of
Help me to Solve the problem...
What I have tried:
Below is php file
<?php
require "connect.php";
$userId = $_GET['UserId'];
$query = "SELECT * FROM `executive` WHERE ExecutiveId = '$userId'";
$result = mysqli_query($conn, $query);
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
echo json_encode($row);
}
} else {
echo "UserId :".$userId."Not Found";
}
mysqli_close($conn);
?>
Below code is from android file
public void getExecutiveInfo(){
String url = "https://sampleappdatabase.000webhostapp.com/SmartKids/ExecutiveInfo.php";
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("Reponse", response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("Error Response", error.toString());
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params = new HashMap<>();
params.put("UserId",UserId);
return params;
}
};
Singleton.getInstance(getApplicationContext()).addToRequestque(jsonObjectRequest);
}