Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse.com: with parseUser, how can I save data in a column I created in parse from the class?

I am using Android Studio for my app and Parse for my database... and on the create an account page I have, it allows the user to enter in first name, last name, email, username, and password.

But my code is using parseUser... I don't know how to set the first and last name in the database. I know setUsername, setPassword, setEmail is a part of it... but what about if you make a column in Parse? How can you add this in your class?

This is a part of my code, what it looks like...my problem is in the else statement I have:

          // Force user to fill up the form
            if (usernametxt.equals("") && passwordtxt.equals("") && emailtxt.equals("")) {
                Toast.makeText(getApplicationContext(),
                        "Please fill in the username, password, and email fields.",
                        Toast.LENGTH_LONG).show();

            } else {
                // Save new user data into Parse.com Data Storage
                ParseUser user = new ParseUser();

                //somehow save first and last name 

                user.setEmail(emailtxt);
                user.setUsername(usernametxt);
                user.setPassword(passwordtxt);
                user.signUpInBackground(new SignUpCallback() {
                    public void done(ParseException e) {
                        if (e == null) {
like image 331
Amna Avatar asked Oct 18 '14 00:10

Amna


1 Answers

Yes, Parse does provide methods to save username, passwords like setUsername(params) and setPassword(params) but if you want to add more data to the tables, you can create more columns according to your needs as I did in this code snippet.

If you have come columns created already in parse back-end like name, phone,address,cityState,companyId, this is how I am doing it.

private void savetoParse() {

        ParseUser user = new ParseUser();
        user.setUsername(usernameEditText.getText().toString());
        user.setPassword(passEditText.getText().toString());
        user.put("name", nameEditText.getText().toString());
        user.setEmail(emailEditText.getText().toString());
        user.put("phone", phoneNoEditText.getText().toString());
        user.put("address", addressEditText.getText().toString());
        user.put("cityState", cityStateEditText.getText().toString());
        user.put("companyID", compSchoolIdEditText.getText().toString());

        user.signUpInBackground(new SignUpCallback() {

            @Override
            public void done(ParseException e) {

                if (e != null) {

                    Toast.makeText(SignupActivityUpdate.this,
                            "Saving user failed.", Toast.LENGTH_SHORT).show();
                    Log.w(TAG,
                            "Error : " + e.getMessage() + ":::" + e.getCode());

                    if (e.getCode() == 202) {

                        Toast.makeText(
                                SignupActivityUpdate.this,
                                "Username already taken. \n Please choose another username.",
                                Toast.LENGTH_LONG).show();
                        usernameEditText.setText("");
                        passEditText.setText("");
                        confirmPassEditText.setText("");

                    }

                } else {

                    Toast.makeText(SignupActivityUpdate.this, "User Saved",
                            Toast.LENGTH_SHORT).show();

                    /*Do some things here if you want to.*/

                }

            }
        });

NOTE : The first params is the column name and second is the value. So, it basically acts like a key value pair.

This is solve the problem..lemme know if this works..good luck..:)

like image 176
mike20132013 Avatar answered Nov 15 '22 00:11

mike20132013