在Laravel

时间:2017-02-26 15:10:08

标签: android laravel android-volley

我正在使用登录/注册系统创建一个应用程序,我正在使用排球库。 当我使用WAMP时,POST方法工作正常但是当我切换到Laravel Homestead时它给了我一个错误。

错误说

BasicNetwork.performRequest: Unexpected response code 500

我已经对这个问题进行了一些搜索,但我很难理解他们的系统。我希望有人可以根据我的计划给我一些建议。

这是我的活动的一部分,从我的php文件获取响应 MainScreen.java

 Response.Listener<String> responseListener = new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                        try {
                            JSONObject jsonresposne = new JSONObject(response);
                            boolean success = jsonresposne.getBoolean("success");

                            if (success) {


                                int user_id = jsonresposne.getInt("uid");
                                Toast.makeText(MainScreen.this,""+user_id,Toast.LENGTH_SHORT).show();
                                Cart c = new Cart();
                                c.getUserID(user_id);

                                Intent intent = new Intent(MainScreen.this, MainActivity.class);

                                startActivity(intent);
                                pd.dismiss();
                            } else {
                                AlertDialog.Builder builder = new AlertDialog.Builder(MainScreen.this);

                                builder.setTitle(Html.fromHtml("<font color='#ff0000'>LOGIN FAILED</font>")).setMessage("email and password did not match")
                                        .setCancelable(false)
                                        .setNegativeButton("Ok", null).create().show();
                                pd.dismiss();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }


                    }
                };

                LoginRequest loginRequest = new LoginRequest(password, email, responseListener);
                RequestQueue queue = Volley.newRequestQueue(MainScreen.this);
                queue.add(loginRequest);

            }

这是我的LoginRequest.java

public class LoginRequest extends StringRequest {
private static final String LOGIN_REQUEST_URL = "http://192.168.1.102:8000/app/login";
private Map<String,String> params;

public LoginRequest(String email, String password, Response.Listener<String> listener){

    super(Request.Method.POST,LOGIN_REQUEST_URL,listener,null);

    params =  new HashMap<>();

    params.put("email",email);
    params.put("password",password);


}

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

}

这是我用POST方法的php文件 的login.php

<?php

$con = mysqli_connect("localhost","homestead","secret","laraveldb");

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

$statement = mysqli_prepare($con,"SELECT id FROM users WHERE email=? AND password=?");
mysqli_stmt_bind_param($statement,"ss",$password,$email);
mysqli_stmt_execute($statement);

mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement,$id);

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

while(mysqli_stmt_fetch($statement)){

    $response["success"] = true;
    $response["uid"] = $id;





}

echo json_encode($response);

?>

0 个答案:

没有答案