我正在创建一个Android应用程序,要求用户在访问应用程序之前先注册。该应用程序功能完美,只有我在注册时面临的一个问题。如果用户使用数据库中已存在的用户名或电子邮件,则应用程序会显示已使用电子邮件或用户名的错误。当我尝试使用不同的用户名和电子邮件时,无论我使用哪种电子邮件或用户名,应用程序都会显示相同的错误,即电子邮件或用户名已经存在,它只是一直说。我使用排球连接应用程序与PHP代码和数据库。我怀疑应用程序会在出现错误时保留缓存。这是用于注册的Android代码:
public void signup() {
if (App.getInstance().isConnected()) {
loading = true;
showpDialog();
CustomRequest jsonReq = new CustomRequest(Request.Method.POST, METHOD_ACCOUNT_SIGNUP, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.e("Profile", "Malformed JSON: \"" + response.toString() + "\"");
if (App.getInstance().authorize(response)) {
Log.e("Profile", "Malformed JSON: \"" + response.toString() + "\"");
App.getInstance().updateGeoLocation();
Intent intent = new Intent(getActivity(), MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
} else {
switch (App.getInstance().getErrorCode()) {
case 300 : {
signupUsername.setError(getString(R.string.error_login_taken));
break;
}
case 301 : {
signupEmail.setError(getString(R.string.error_email_taken));
break;
}
default: {
Log.e("Profile", "Could not parse malformed JSON: \"" + response.toString() + "\"");
break;
}
}
}
loading = false;
hidepDialog();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), getText(R.string.error_data_loading), Toast.LENGTH_LONG).show();
loading = false;
hidepDialog();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("username", username);
params.put("fullname", fullname);
params.put("password", password);
params.put("photo", photo);
params.put("email", email);
params.put("language", language);
params.put("facebookId", facebookId);
params.put("sex", Integer.toString(sex));
params.put("year", Integer.toString(year));
params.put("month", Integer.toString(month));
params.put("day", Integer.toString(day));
params.put("clientId", CLIENT_ID);
params.put("gcm_regId", App.getInstance().getGcmToken());
return params;
}
};
App.getInstance().addToRequestQueue(jsonReq);
} else {
Toast.makeText(getActivity(), R.string.msg_network_error, Toast.LENGTH_SHORT).show();
}
}
和php代码:
public function isEmailExists($user_email)
{
$stmt = $this->db->prepare("SELECT id FROM users WHERE email = (:email) LIMIT 1");
$stmt->bindParam(':email', $user_email, PDO::PARAM_STR);
if ($stmt->execute()) {
if ($stmt->rowCount() > 0) {
return true;
}
}
return false;
}