Entertainment

Saturday 19 March 2016

Android Login From Php


Creating MySQL Database

  • Go to your phpmyadmin database (I am using my localhost from wamp server).
  • Create a simple table named users of 3 columns (userid, username and password). userid will be the primary key and make it auto increment.

Creating PHP Script

  • Create a php script. Our script will get two post values username and password from our android app.
  • Then we will check that the given username or password exist or not?
  • If exist we will echo a message success
  • Else we will echo a message failure

login.php 

My userprofile.java file


package com.example.android_php;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;


public class UserProfile extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome);

        Intent intent = getIntent();
        String username = intent.getStringExtra(MainActivity.USER_NAME);

        TextView textView = (TextView) findViewById(R.id.textView3);

        textView.setText("Welcome "+username);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}


                                                       Now you can test your application.

Total Page View

website counter
Stats For Free

No comments:

Post a Comment