无法使用Android中的Volley库从MySQL数据库中选择数据

时间:2017-07-14 20:01:28

标签: java php android mysql android-volley

我想使用该表中的id从MySQL数据库中选择两个字符串数据,然后我想在两个EditText中显示它们。我真的不知道它为什么不起作用。

我的表有5列:user_id, resumeSubject, resumeText, email, fullname。在我的表格中,我有一个特定的行,我想要它resumeSubjectresumeText字段。

这是我的PHP文件:

<?php
$con = mysqli_connect("HOST", "UserName", "Password", "Database Name");

$user_id = $_POST["user_id"];
$email = $_POST["email"];

$statement = mysqli_prepare($con, "SELECT * FROM resumeUserList WHERE user_id = ?");
mysqli_stmt_bind_param($statement, "i", $user_id);
mysqli_stmt_execute($statement);

mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $user_id, $resumeSubject, $resumeText, $email, $fullname);

$response = array();
$response["success"] = false;  

while(mysqli_stmt_fetch($statement)){
    $response["success"] = true;        
    $response["resumeSubject"] = $resumeSubject;
    $response["resumeText"] = $resumeText;
}

echo json_encode($response); ?>

这是我的申请类:

public class Request extends StringRequest {
    private static final String REQUEST_URL = "URL";

    private Map<String, String> params;

    public Request(int user_id, Response.Listener<String> listener) {
        super(Method.POST, REQUEST_URL, listener, null);
        params = new HashMap<>();
        params.put("user_id", user_id +"");
    }

    @Override
    public Map<String, String> getParams() {
        return params;
    }
}

这是我的ReceiveActivity

public class Receive extends Activity {

    private static int user_id;
    private static String fullname, email;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_receive);

        final EditText resumeSubjectText = (EditText) findViewById(R.id.subjectId);
        final EditText resumeTextText = (EditText) findViewById(R.id.massageId);

        Response.Listener<String> responseListener = new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    JSONObject jsonResponse = new JSONObject(response);
                    boolean success = jsonResponse.getBoolean("success");

                    if (success) {
                        String resumeSubject = jsonResponse.getString("resumeSubject");
                        String resumeText = jsonResponse.getString("resumeText");

                        resumeSubjectText.setText(resumeSubject);
                        resumeTextText.setText(resumeText);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        };

        Request request = new Request(user_id, responseListener);
        RequestQueue queue = Volley.newRequestQueue(CommonUserList_User.this);
        queue.add(request);  }
}

我的错误是什么?

0 个答案:

没有答案