在数据库textview中拉数据
要打印。但值是空的。
请求处理中是否有错误?或请求过程应该如何?
php中有错误吗?
下面是我的android和php代码。
userTc = findViewById(R.id.tc_no);
userName = findViewById(R.id.name);
userSurname = findViewById(R.id.surname);
userType = findViewById(R.id.type);
JSONObject jsonObject=new JSONObject();
try {
jsonObject.put("tc",userTc);
} catch (JSONException e) {
e.printStackTrace();
}
final String url = "http:/database/show.php";
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
(Request.Method.GET, url, jsonObject, new
Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
userTc.setText(response.getString("tc"));
userName.setText(response.getString("name"));
userSurname.setText(response.getString("surname"));
userType.setText(response.getString("type"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "error" + error,
Toast.LENGTH_SHORT).show();
}
});{
}
$tc=$_GET["tc"];
$sql=$conn->prepare("SELECT tc,name,surname,type FROM personel");
$sql->execute();
$fetch=$sql->fetch(PDO::FETCH_ASSOC);
echo json_encode(array("tc"=>$fetch["tc"],"name"=>$fetch["name"],"surname"=>$fetch["surname"],"type"=>$fetch["type"]));