Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 响应侦听器工作不正常_Php_Android - Fatal编程技术网

Php 响应侦听器工作不正常

Php 响应侦听器工作不正常,php,android,Php,Android,我有一个注册活动和一个登录活动,我想在用户成功注册时打开登录活动。但在我的情况下,注册后我没有获得登录活动。用户在数据库表中成功注册。 下面是响应侦听器的代码 private void registerUser(final String name, final String email, final String password) { // Tag used to cancel the request String tag_s

我有一个注册活动和一个登录活动,我想在用户成功注册时打开登录活动。但在我的情况下,注册后我没有获得登录活动。用户在数据库表中成功注册。 下面是响应侦听器的代码

private void registerUser(final String name, final String email,
                          final String password) {
    // Tag used to cancel the request
    String tag_string_req = "req_register";

    pDialog.setMessage("Registering ...");
    showDialog();

    StringRequest strReq = new StringRequest(Method.POST,
            AppConfig.URL_REGISTER, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            Log.d(TAG, "Register Response: " + response);
            hideDialog();

            try {
                JSONObject jObj = new JSONObject(response);

                boolean error = jObj.getBoolean("error");
                if (!error) {
                    // User successfully stored in MySQL
                    // Now store the user in sqlite


                    JSONObject user = jObj.getJSONObject("user");
                    String name = user.getString("name");
                    String email = user.getString("email");
                    String created_at = user
                            .getString("created_at");

                    // Inserting row in users table
                    db.addUser(name, email,  created_at);

                    Toast.makeText(getApplicationContext(), "User successfully registered. Try login now!", Toast.LENGTH_LONG).show();

                    // Launch login activity
                    Intent intent = new Intent(
                            RegisterActivity.this,
                            LoginActivity.class);
                    startActivity(intent);
                    finish();
                } else {

                    // Error occurred in registration. Get the error
                    // message
                    String errorMsg = jObj.getString("error_msg");
                    Toast.makeText(getApplicationContext(),
                            errorMsg, Toast.LENGTH_LONG).show();
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(TAG, "Registration Error: " + error.getMessage());
            Toast.makeText(getApplicationContext(),
                    error.getMessage(), Toast.LENGTH_LONG).show();
            hideDialog();
        }
    }) {

        @Override
        protected Map<String, String> getParams() {
            // Posting params to register url
            Map<String, String> params = new HashMap<String, String>();
            params.put("name", name);
            params.put("email", email);
            params.put("password", password);

            return params;
        }

    };

    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}
private void registerUser(最终字符串名称、最终字符串电子邮件、,
最终字符串(密码){
//用于取消请求的标记
String tag_String_req=“req_register”;
pDialog.setMessage(“注册…”);
showDialog();
StringRequest strReq=新的StringRequest(Method.POST,
AppConfig.URL\u寄存器,新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
Log.d(标签,“寄存器响应:”+响应);
hideDialog();
试一试{
JSONObject jObj=新的JSONObject(响应);
布尔错误=jObj.getBoolean(“错误”);
如果(!错误){
//用户成功存储在MySQL中
//现在将用户存储在sqlite中
JSONObject user=jObj.getJSONObject(“用户”);
字符串名称=user.getString(“名称”);
String email=user.getString(“电子邮件”);
在=用户处创建的字符串
.getString(“创建于”);
//在用户表中插入行
db.addUser(姓名、电子邮件、创建地址);
Toast.makeText(getApplicationContext(),“用户已成功注册。请立即尝试登录!”,Toast.LENGTH\u LONG.show();
//启动登录活动
意图=新意图(
RegisterActivity.this,
物流活动(类);
星触觉(意向);
完成();
}否则{
//注册时出错。获取错误信息
//信息
String errorMsg=jObj.getString(“error_msg”);
Toast.makeText(getApplicationContext(),
errorMsg,Toast.LENGTH_LONG).show();
}
}捕获(JSONException e){
e、 printStackTrace();
}
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
Log.e(标记,“注册错误:+Error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(),Toast.LENGTH_LONG).show();
hideDialog();
}
}) {
@凌驾
受保护的映射getParams(){
//发布参数以注册url
Map params=新的HashMap();
参数put(“名称”,名称);
参数put(“电子邮件”,电子邮件);
参数put(“密码”,密码);
返回参数;
}
};
//将请求添加到请求队列
AppController.getInstance().addToRequestQueue(streq,标记字符串请求);
}
  • 2 php代码

    <?php
        require_once 'include/DB_Functions.php';
    
        $db = new DB_Functions();
    
        $response = array("error" => FALSE);
    
    
        if (isset($_REQUEST['name']) && isset($_REQUEST['email']) && isset($_REQUEST['password'])) {
    
    
         // receiving the REQUEST params
            $name = $_REQUEST['name'];
            $email = $_REQUEST['email'];
    
          $password = $_REQUEST['password'];
    
            if ($db->isUserExisted($email)) {
    
                $response["error"] = TRUE;
    
             $response["error_msg"] = "User already existed with " . $email;
    
            echo json_encode($response);
    
          } else {
    
         $user = $db->storeUser($name, $email, $password);
    
          if ($user) {
    
             $response["error"] = FALSE;
    
    
               $response["user"]["name"] = $user["name"];
    
              $response["user"]["email"] = $user["email"];
    
             $response["user"]["created_at"] = $user["created_at"];
    
              $response["user"]["updated_at"] = $user["updated_at"];
    
             echo json_encode($response);
    
          } else {
    
               $response["error"] = TRUE;
    
             $response["error_msg"] = "Unknown error occurred in registration!";
    
                echo json_encode($response);
    
            }
            }
        } else {
    
          $response["error"] = TRUE;
    
          $response["error_msg"] = "Required parameters (name, email or password) is missing!";
    
          echo json_encode($response);
        }
    ?>
    
    
    
## Write the Intent this way ##
Intent intent = new Intent(
                        RegisterActivity.this,
                        LoginActivity.class);
              RegisterActivity.this.startActivity(intent);