Android create User Registration form with PHP MySQL insert data online example tutorial

How to make user signup form inside android app which can store all details directly on server in MySQL db.

In this tutorial we are simply getting data our SIGN-UP from’s inside edittext. After getting values we are checking whether edittext is empty or not, because we do not send empty values on server. So one by one we have check all the form fields and after that we give it to our SendDataToServer() method which will parse this whole data and send directly into online MySQL database which is present on our website. So here is the complete step by step tutorial for Android create User Registration form with PHP MySQL insert data online example tutorial.

android-project-download-code-button

List of PHP files used in this project to get data which is sent by android app to insert into MySQL db.

  1. insert-registration-data.php .

List of Main android project files :

  1. MainActivity.java .
  2. activity_main.xml .
  3. AndroidManifest.xml .

Android create User Registration form with PHP MySQL insert data online example tutorial.

Code for MainActivity.java file.

 package com.userregistrationformphpmysql_android_examples.com;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

 EditText name,email,password ;
 String Getname,GetEmail,GetPassword ;
 Button register ;
 String DataParseUrl = "http://androidblog.esy.es/test/insert-registration-data.php" ;
 Boolean CheckEditText ;
 String Response;
 HttpResponse response ;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 name = (EditText)findViewById(R.id.editText1);
 email = (EditText)findViewById(R.id.editText2);
 password = (EditText)findViewById(R.id.editText3);
 
 register = (Button)findViewById(R.id.button1) ;
 
 register.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 
 GetCheckEditTextIsEmptyOrNot();
 
 if(CheckEditText){

 SendDataToServer(Getname, GetEmail, GetPassword);
 
 }
 else {
 
 Toast.makeText(MainActivity.this, "Please fill all form fields.", Toast.LENGTH_LONG).show();
 
 }
 
 }
 });
 }
 
 public void GetCheckEditTextIsEmptyOrNot(){
 
 Getname = name.getText().toString();
 GetEmail = email.getText().toString();
 GetPassword = password.getText().toString();
 
 if(TextUtils.isEmpty(Getname) || TextUtils.isEmpty(GetEmail) || TextUtils.isEmpty(GetPassword))
 {
 
 CheckEditText = false;
 
 }
 else {
 
 CheckEditText = true ;
 }
 
 }
 
 public void SendDataToServer(final String name, final String email, final String password){
 class SendPostReqAsyncTask extends AsyncTask<String, Void, String> {
 @Override
 protected String doInBackground(String... params) {
 
 String QuickName = name ;
 String QuickEmail = email ;
 String QuickPassword = password;
 
 List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
 
 nameValuePairs.add(new BasicNameValuePair("name", QuickName));
 nameValuePairs.add(new BasicNameValuePair("email", QuickEmail));
 nameValuePairs.add(new BasicNameValuePair("password", QuickPassword));
 
 try {
 HttpClient httpClient = new DefaultHttpClient();
 
 HttpPost httpPost = new HttpPost(DataParseUrl);
 
 httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
 
 HttpResponse response = httpClient.execute(httpPost);
 
 HttpEntity entity = response.getEntity();
 
 
 } catch (ClientProtocolException e) {
 
 } catch (IOException e) {
 
 }
 return "Data Submit Successfully";
 }
 
 @Override
 protected void onPostExecute(String result) {
 super.onPostExecute(result);
 
 Toast.makeText(MainActivity.this, "Data Submit Successfully", Toast.LENGTH_LONG).show();
 
 }
 }
 SendPostReqAsyncTask sendPostReqAsyncTask = new SendPostReqAsyncTask();
 sendPostReqAsyncTask.execute(name, email, password);
 }
 
 }

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.userregistrationformphpmysql_android_examples.com.MainActivity"
 android:background="#02c3d4" >

 <TextView
 android:id="@+id/textView1"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:text="REGISTER HERE"
 android:gravity="center"
 android:textAppearance="?android:attr/textAppearanceLarge"
 android:textColor="#fbfefd"
 
 />

 <EditText
 android:id="@+id/editText1"
 android:layout_width="fill_parent"
 android:layout_height="50dp"
 android:layout_below="@+id/textView1"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="24dp"
 android:ems="10"
 android:hint="ENTER YOUR NAME"
 android:background="#fbfefd"
 android:gravity="center" >
 </EditText>

 <EditText
 android:id="@+id/editText2"
 android:layout_width="fill_parent"
 android:layout_height="50dp"
 android:layout_below="@+id/editText1"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="24dp"
 android:ems="10"
 android:hint="ENTER YOUR EMAIL ID"
 android:inputType="textEmailAddress"
 android:background="#fbfefd"
 android:gravity="center" >
 <requestFocus />
 </EditText>

 <EditText
 android:id="@+id/editText3"
 android:layout_width="fill_parent"
 android:layout_height="50dp"
 android:layout_marginTop="24dp"
 android:layout_below="@+id/editText2"
 android:layout_centerHorizontal="true"
 android:ems="10"
 android:hint="ENTER YOUR PASSWORD"
 android:inputType="textPassword"
 android:background="#fbfefd"
 android:gravity="center" />

 <Button
 android:id="@+id/button1"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_below="@+id/editText3"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="24dp"
 android:text="REGISTER"
 android:background="#d8dbdb"
 />

</RelativeLayout>

Code for AndroidManifest.xml file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.userregistrationformphpmysql_android_examples.com"
 android:versionCode="1"
 android:versionName="1.0" >

 <uses-sdk
 android:minSdkVersion="8"
 android:targetSdkVersion="21" />

 <uses-permission android:name="android.permission.INTERNET"/>
 
 <application
 android:allowBackup="true"
 android:icon="@drawable/ic_launcher"
 android:label="@string/app_name"
 android:theme="@style/AppTheme" >
 <activity
 android:name=".MainActivity"
 android:label="@string/app_name" >
 <intent-filter>
 <action android:name="android.intent.action.MAIN" />

 <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
 </activity>
 </application>

</manifest>

PHP FILES :

Code for insert-registration-data.php file.

<?php

//This script is designed by Android-Examples.com
//Define your host here.
$hostname = "mysql.hostinger.in";
//Define your database username here.
$username = "u288012116_new";
//Define your database password here.
$password = "1234567890";
//Define your database name here.
$dbname = "u288012116_new";
 
 $con = mysqli_connect($hostname,$username,$password,$dbname);
 
 $name = $_POST['name'];
 $email = $_POST['email'];
 $password = $_POST['password'];
 
 
 $Sql_Query = "insert into registration (name,email,password) values ('$name','$email','$password')";
 
 if(mysqli_query($con,$Sql_Query)){
 
 echo 'Data Inserted Successfully';
 
 }
 else{
 
 echo 'Try Again';
 
 }
 mysqli_close($con);
?>

Screenshot :

user-signup-form

Android create User Registration form with PHP MySQL

Database Screenshot :

get-data-db

Click here to download Android create User Registration form with PHP MySQL insert data online example tutorial project with source code.