![](/img/trans.png)
[英]Why is it that i am still not able to create a new directory in sdcard after capturing an image for my app?
[英]Why my method is not able to check if my user is exist or not before they are able to create a new account?
我添加了檢查數據庫中用戶的email是否存在的方法。 例如,現有用戶不能使用相同的 email 重新注冊帳戶。 但是我仍然可以使用相同的 email 注冊我的帳戶。 我的代碼沒有錯誤。 我不知道問題出在哪里。 大家能幫我解決這個問題嗎?
這是我在 DatabaseHelper.JAVA 中添加的方法
public boolean userExists (String email){
String [] columns = {C_EMAIL};
SQLiteDatabase db = getReadableDatabase();
String selection = C_EMAIL + "=?";
String selectionArgs []= { email };
Cursor cursor = db.query(TABLE_NAME,columns,selection,selectionArgs,null,null,null);
return true;
}
這是我的 MainActivity.Java
private void getData() {
email = "" + Pemail.getText().toString().trim();
name = "" + Pname.getText().toString().trim();
age = "" + PAge.getText().toString().trim();
phone = "" + Pphone.getText().toString().trim();
preferenceselected = "" + Ppreferenceselected.getText().toString().trim();
password = "" + Ppassword.getText().toString().trim();
if (email.isEmpty() || name.isEmpty() || age.isEmpty() || phone.isEmpty() || preferenceselected.isEmpty() || password.isEmpty()) {
Toast.makeText(this, "Please fill all the information", Toast.LENGTH_SHORT).show();
if (dbHelper.userExists(email)){
Toast.makeText(this, "User Exist", Toast.LENGTH_SHORT).show();
return;
}
}
String timeStamp = "" + System.currentTimeMillis();
boolean id = dbHelper.insertInfo(
"" + imageUri,
"" + email,
"" + name,
"" + age,
"" + phone,
"" + preferenceselected,
"" + password,
""+timeStamp,
""+timeStamp
);
Toast.makeText(this, "Account Created", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this, setting.class);
startActivity(intent);
}
您必須在第一個 if 語句之后檢查用戶是否存在:
if (email.isEmpty() || name.isEmpty() || age.isEmpty() || phone.isEmpty() || preferenceselected.isEmpty() || password.isEmpty()) {
Toast.makeText(this, "Please fill all the information", Toast.LENGTH_SHORT).show();
return;
}
if (dbHelper.userExists(email)){
Toast.makeText(this, "User Exist", Toast.LENGTH_SHORT).show();
return;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.