mysql - I am having trouble with the logic in my code in android studio -


this code supposed serve on purpose, verify email address has been added database of "profiles" has not been entered before. after user enters relevant data, , attempts verify data legitimate entry, email address checked against other entries in database (because emails unique part of set of entries other nickname)and if email unique database, entry accepted , new column should created in database(which is). problem email accepted unique.

this code shows how entries weeded out make sure fit convention of sign sheets

public void registeraccount(view view) {     loginentries entries = new loginentries(             newemailaddressinput.gettext().tostring(),             newpasswordinput.gettext().tostring(),             newfirstnameinput.gettext().tostring(),             newlastnameinput.gettext().tostring(),             newnickname.gettext().tostring(),fullphonenumber);     string istempemail = newemailaddressinput.gettext().tostring();      string istemppass = newpasswordinput.gettext().tostring();     string confirmpasswordholder = confirmnewpasswordinput.gettext().tostring();      if (textutils.isempty(istempemail) && textutils.isempty(istemppass)) {         toast.maketext(this, "enter email , password", toast.length_long).show();         newemailaddressinput.settext("");         newpasswordinput.settext("");         confirmnewpasswordinput.settext("");     } else if (textutils.isempty(istempemail) && !textutils.isempty(istemppass)) {         toast.maketext(this, "enter email", toast.length_long).show();         newemailaddressinput.settext("");         newpasswordinput.settext("");         confirmnewpasswordinput.settext("");     } else if (!textutils.isempty(istempemail) && textutils.isempty(istemppass)) {         toast.maketext(this, "enter password", toast.length_long).show();         newemailaddressinput.settext("");         newpasswordinput.settext("");         confirmnewpasswordinput.settext("");     } /*temporary while app offline, when app operational, different prompt search web verify email address*/     else if (!istempemail.endswith("@gmail.com") && !istempemail.endswith("@yahoo.com") && !istempemail.endswith("@aol.com") && !istempemail.endswith("@hotmail.com")) {         toast.maketext(this, "not valid email address, trying again", toast.length_long).show();         newemailaddressinput.settext("");         newpasswordinput.settext("");         confirmnewpasswordinput.settext("");     } else if (!dbhandler.signupemailcheck(istempemail)) {         toast.maketext(this, "email used, please try again", toast.length_long).show();         newemailaddressinput.settext("");         newpasswordinput.settext("");         confirmnewpasswordinput.settext("");     } else if (!confirmpasswordholder.equals(istemppass)) {         toast.maketext(this, "passwords don't match!", toast.length_long).show();         newpasswordinput.settext("");         confirmnewpasswordinput.settext("");         areacodeinput.settext("");         firstthreedigitsinput.settext("");         finalfourdigitsinput.settext("");     } else{         toast.maketext(this, "saved!", toast.length_long).show();         dbhandler.addentry(entries);// adds entries database         printdatabase();        } } 

this code, in above method issue @ hand. when email handed on code, calls method below database handler class.

else if (!dbhandler.signupemailcheck(istempemail)) {             toast.maketext(this, "email used, please try again", toast.length_long).show();             newemailaddressinput.settext("");             newpasswordinput.settext("");             confirmnewpasswordinput.settext(""); 

this method takes email entry , uses call , other entries same name (as understand work, wrong why writing question) if getcolumncount() function zero, method returns true shows makes if statement false, dictates user use email. never happens. i've tried different positions of true, false returns, none of combinations lead right conclusion.

   public boolean signupemailcheck(string emailentry){     //checks if new email entry exists in database      integer holder;     sqlitedatabase db = getwritabledatabase();     string query = "select * " + table_loginentries + " " + column_emailaddress  + "=\"" + emailentry + "\"";     cursor c = db.rawquery(query,null);     holder = c.getcolumncount();     if (holder > 0) {         db.close();         c.close();         return true;     } else {         db.close();         c.close();         return false;     } } 

this method called enter data database

public void addentry(loginentries entry){     contentvalues values = new contentvalues();      values.put(column_emailaddress,entry.get_emailaddress());     values.put(column_password,entry.get_password());     values.put(column_firstname,entry.get_firstname());     values.put(column_lastname,entry.get_lastname());     values.put(column_phonenumber,entry.get_phonenumber());     values.put(column_nickname,entry.get_nickname());     sqlitedatabase db = getwritabledatabase();     db.insert(table_loginentries, null, values);     db.close(); } 

try rewrite query this, make sure emailentry not null.

 string query = "select * " + table_loginentries + " " + column_emailaddress  + "=?";  cursor c = db.rawquery(query, new string[] { emailentry }); 

also check if cursor empty following methods:

if(!c.movetofirst() || c.getcount() == 0){     ...     return true; // cursor empty, email doesn't exist }else{     return false; // cursor not empty, email exists } 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -