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.
List of PHP files used in this project to get data which is sent by android app to insert into MySQL db.
- insert-registration-data.php .
List of Main android project files :
- MainActivity.java .
- activity_main.xml .
- 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.