duanpao4522 2017-03-27 13:17
浏览 38
已采纳

登录过程不起作用

I'm making a login service in Android application, but I have a problem when I login. After I register a sample data and try to login, the login button responds with a message 'BasicNetwork.performRequest: Unexpected response code 500 for http://ekb2011.cafe24.com/Login.php'.

This is my PHP code for login.

<?php
    $con = mysqli_connect("localhost","ekb2011","*********","ekb2011");
    
    $userID = $_POST["userID"];
    $userPassword = $_POST["userPassword"];
    
    $statement = mysqli_prepare($con, "SELECT * FROM USER WHERE userID = ? AND userPassword = ?");
    mysqli_stmt_bind_param($statement, "ss", $userID, $userPassword);
    mysqli_stmt_execute($statement);
    
    mysqli_stmt_store_result($statement);
    mysqli_stmt_bind_result(&statement, $userID, $userPassword, $userName);
    
    $response = array();
    $response["success"] = false;
    
    while(mysqli_stmt_fetch($statement)){
        $response["success"] = true;
        $response["userID"] = $userID;
        $response["userPassword"] = $userPassword;
        $response["userName"] = $userName;  
    }
    echo json_encode($response);
?>

And the following are java codes executed in my application.

LoginActivity.java

public class LoginActivity extends AppCompatActivity {

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

    final EditText idText=(EditText)findViewById(R.id.idText);
    final EditText passwordText=(EditText)findViewById(R.id.passwordText);

    final Button loginButton=(Button)findViewById(R.id.loginButton);
    final TextView registerButton = (TextView)findViewById(R.id.registerButton);
    final CheckBox loginCheckBox = (CheckBox)findViewById(R.id.logincheckBox);



    registerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent registerIntent=new Intent(LoginActivity.this, RegisterActivity.class);
            LoginActivity.this.startActivity(registerIntent);
        }
    });
    loginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            final String userID=idText.getText().toString();
            final String userPassword=passwordText.getText().toString();

            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 userID=jsonResponse.getString("userID");
                            String userPassword=jsonResponse.getString("userPassword");
                            Intent intent=new Intent(LoginActivity.this, MainActivity.class);
                            intent.putExtra("userID",userID);
                            intent.putExtra("userPassword",userPassword);
                            LoginActivity.this.startActivity(intent);
                        }
                        else{
                            AlertDialog.Builder builder=new AlertDialog.Builder(LoginActivity.this);
                            builder.setMessage("Failed to Login")
                                    .setNegativeButton("Try Again", null)
                                    .create()
                                    .show();
                        }
                    } catch(Exception e){
                        e.printStackTrace();
                    }
                }
            };

            LoginRequest loginRequest=new LoginRequest(userID, userPassword, responseListener);
            RequestQueue queue= Volley.newRequestQueue(LoginActivity.this);
            queue.add(loginRequest);
        }
    });

}
}

LoginRequest.java

public class LoginRequest extends StringRequest {
    final static private String URL="http://ekb2011.cafe24.com/Login.php";
    private Map<String, String> parameters;
    public LoginRequest(String userID, String userPassword, Response.Listener<String> listener){
        super(Method.POST, URL, listener, null);
        parameters=new HashMap<>();
        parameters.put("userID", userID);
        parameters.put("userPassword", userPassword);

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

}

How can I fix this problem?

</div>
  • 写回答

1条回答 默认 最新

  • dougaoshang0237 2017-03-27 13:42
    关注

    Change this:

    mysqli_stmt_bind_result(&statement, $userID, $userPassword, $userName);
    

    in this:

    mysqli_stmt_bind_result($statement, $userID, $userPassword, $userName);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?