dimanche 11 octobre 2015

Table Name has no Column for Name Android SQLite PHP

I'm populating my SQLiteDatabase with PHP Script for the login credentials and Account Information. Even the login is working fine the SQLite have error for my gender name in column I don't know what I'm missing with this. Can someone point it out for me? Cu'z me and my friend can't find it and were both new to Android Development.

Here is the Error

>     E/SQLiteDatabase﹕ Error inserting gender=tuesdaycross04@gmail.com bday=24242 email=Male address=asdasd mobile=1995-03-03
> full_name=Arnold
>         android.database.sqlite.SQLiteException: table accounts has no column named gender (code 1): , while compiling: INSERT INTO
> accounts(gender,bday,email,address,mobile,full_name) VALUES
> (?,?,?,?,?,?)

SQLiteHelper

    private static final int DATABASE_VERSION = 1;
        // Database Name
        private static final String DATABASE_NAME = "brm_dbs";
        // Login table name
        private static final String TABLE_LOGIN = "accounts";
        // Login Table Columns names
        private static final String KEY_ID = "id";
        private static final String KEY_NAME = "full_name";
        private static final String KEY_ADDRESS = "address";
        private static final String KEY_MOBILE = "mobile";
        private static final String KEY_EMAIL = "email";
        private static final String KEY_UID = "uid";
        private static final String KEY_CREATED_AT = "created_at";
        private static final String KEY_BDAY = "bday";
        private static final String KEY_GENDER = "gender";

        public SQLiteHandler(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }
        // Creating Tables
        @Override
        public void onCreate(SQLiteDatabase db) {
            String CREATE_LOGIN_TABLE = "CREATE TABLE " + TABLE_LOGIN + "("
                    + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
                    + KEY_ADDRESS + " TEXT," + KEY_MOBILE + " INTEGER,"
                    + KEY_EMAIL + " TEXT UNIQUE," + KEY_UID + " TEXT,"
                    + KEY_CREATED_AT + " TEXT," + KEY_BDAY + " TEXT,"
                    + KEY_GENDER + " TEXT" + ");";
            db.execSQL(CREATE_LOGIN_TABLE);

            Log.d(TAG, "Database tables created");
        }

public void getloginUser(String full_name, String address,
                             String bday, String gender,
                             String mobile, String email) {
        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        //values.put(KEY_UNIQUE_ID, unique_id);
        values.put(KEY_NAME, full_name); // Name
        values.put(KEY_ADDRESS, address); // address
        values.put(KEY_BDAY, bday); // BDAY
        values.put(KEY_GENDER, gender); // GENDER
        values.put(KEY_MOBILE, mobile); // mobile
        values.put(KEY_EMAIL, email); // Email


        // Inserting Row
        long id = db.insert(TABLE_LOGIN, null, values);
        db.close(); // Closing database connection
        Log.d(TAG, "New user inserted into sqlite: " + id);
    }

Inserting to SQLite via Login credentials

try {
                    JSONObject jObj = new JSONObject(response);
                    boolean error = jObj.getBoolean("error");
                    // Check for error node in json
                    if (!error) {
                        // user successfully logged in
                        // Create login session
                        session.setLogin(true);
                        JSONObject user = jObj.getJSONObject("user");
                        String full_name = user.getString("full_name");
                        String address = user.getString("address");
                        String mobile = user.getString("mobile");
                        String email = user.getString("email");
                        String bday = user.getString("bday");
                        String gender = user.getString("gender");
                        // Inserting row in users table
                        db.getloginUser(full_name, address, mobile, email, bday, gender);
                        // Launch main activity

                        // Launch main activity
                        Intent intent = new Intent(Loign.this,
                                MainActivity.class);
                        startActivity(intent);
                        finish();

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

Aucun commentaire:

Enregistrer un commentaire