Send Data From Android Device To Php Server

In this tutorial, we will show you how android device and PHP server will communicate with each other using httpclient or httppost method. When you are going to implement your idea into an android app you need a server where you will store DATA & get DATA from server. These ‘DATA’ could be user profile, last purchase details, users activity, time, data, images etc. In this tutorial we will first create an login form for user. After submit button press user’s data like username , lastname , password and time wi send to our PHP server database. Summary steps to develop an android client and PHP server communication application :

1) Create User login Form in android app.
2) Get form data using MainActivity.class(value holder class).
3) Create Database table to store user details.
4) Create PHP server to accept data from android client.
5) Run App in Real Device using USB Debugging.

Android client send Data to PHP server

Login & Download source code



Create User Login Form in Android App

Create new android project in android studio. Go to File–> New –> New Project and give any name to your app (Mine was SendDataToPHP). Now on activity_main.xml create four EditView, One TextView. one Spinner & one Button.


User can write any text in this box. In our case user will type username, password, phone number & hint answer


Display any text to user like ” Create login “.


A Dropdown list is called Spinner in android. In our case we will put some questions in this list

senddata login form


Get Form Data Using MainActivity.class(value holder class)

Now We have form layout ready & we will get all form data value using MainActivity.class file & will send data to PHP server in next step. First declare all TextView ,EditView, Spinner & button above onCreate(Bundle savedInstanceState) method. I hope you already know how define EditView with EditView Id mention in activity_main.xml file. For beginners i write these 2 lines. Inside onCreate() connect EditView to EditView id define in activity_main.xml file(like

If your login form contains security questions as a dropdown list(Spinner). See last line in above code i have added spinner for hint questions. To add questions in spinner you have to create a ArrayList object. Add all questions to ArrayList & Finally add ArrayList to spinner using default Adapter called ArrayAdapter.

Now when user press submit button- first check whether all field are empty or not. Second check which language (Keyboard language- English, Hindi, etc.) your server suppose to be support. Here i am considering first case only- check all field are none empty. Once it is clear that user filled all the required fields properly then we need a ArrayList that holder all data which will be pass to AsyncTask. AsyncTask is use for all network related task. AsyncTask execute on separate thread in background not in Main thread. Android OS does not allow network task to be execute on main thread.

AsyncTask have three sections.

1) onPreExecute() – prepare task related functions like show progress bar to user.
2) doInBackground() – perform background task like send request to server.
3) onPostExecute() – present server response to user screen on main thread.

Complete MainActivity.class Code

Inside doInBackground(ArrayList… alldata) we will again retrieve value from mylist( ArrayList ).Because we are using ArrayList which is like “phonenumber” =” 123456″ where phonenumber is ID for 123456. These IDs are used in PHP to fetch each data value. So we have to assign an ID to each data value. Remember NameValuePair method is included in httpclient library. So make sure to add httpclient dependency on gradle file(app module). Otherwise it show “can’t resolved method” error.

Create Database table to store user details.

Now we will do Server side coding and table creating task. First we will create SQL database table using PHPMyAdmin. Please watch below mansion video. Follow all the step describe in this video. Remember There are two type of hosting provider -1) Window hosting 2) Linux Hosting.I am using Linux hosting which provides CPanal. If you are using windows hosting, Database & table creation task is same for both type of Hosting plan windows & linux. If you are going to purchase hosting i will suggest you to buy Linux hosting. CPanel providers lot of option as you require for website development.


Create Database & table using PHPmyAdmin


Create PHP Page to accept data from android client.

Now create php page which will receive data from android app. The name of php file will StoreUserData.php. See android code where user data are send to this URL “ In StoreUserData.php file first store all value in a variable. Then use simple SQL INSERT query for storing data into table.


Run App in Real Device using USB Debugging

There you can see then user type username, password & other details and hit submit button request sent to php server page. In Response to request from user PHP server reply with username & password which user has written in android app form.


Run code in Emulator OR in Real Device


Login & Download source code



Download Source Code

* indicates required

Posted in andorid.

kamal bunkar

I Am Post Graduation (M.Tech. C.S.E) from VNIT, Nagpur. I Have Published Two Research Paper On International Journal. My Apps on Google Play Store- Sanyukt Parivar(Mp Police ), NOTOtag- Digital Chhindwara, The Tubby-VoiceRecognizer & More.
Contact me at

One Comment

  1. Pingback: Android Login & Registration Setup Form with Material Design – BlueApp Software Blog

Leave a Reply

Your email address will not be published. Required fields are marked *