Android Login and Registration with PHP, MySQL and SQLite

In my previous article Android Login and Registration Screen Design I explained designing the login and registration interfaces. But it has no real time functionality. In this tutorial I am going to explain how to build complete login and registration system in android using PHP, MySQL and SQLite. Also this tutorial covers how to build simple API using PHP and MySQL.

API (Application Programming Interface)

To interact with MySQL database we need to build a REST API first. REST Api job is to get the request from client, interact with database and finally give the response back to client. So we’ll create a simple PHP, MySQL API first. Our API do’s below jobs.

1. Downloading & Installing WAMP

Download & Install WAMP server from www.wampserver.com/en/. Once installed, launch the program from Start ⇒ All Programs ⇒ WampServer ⇒ StartWampServer. If you are on Mac, alternatively you can use MAMP for the same.

5. Create DB_Functions.php inside include with below content. This file contains functions to store user in database, get user from database. You can also add methods like update user, delete user.unique id – I am generating unique user id in php using uniqid(”, true) function. Sample user id will be like 4f074eca601fb8.88015924Encrypted Password – The passwords are stored using base64_encode method. Each password needs two columns to store it in database. One is to store encrypted password and other is to store salt used to encrypt the password.

3.1 Registration Endpoint

Now we have all the required classes ready. Let’s start creating the endpoint for user registration. This endpoint accepts name, email and password as POST parameters and store the user in MySQL database.

3.2 Login Endpoint

Just like registration, we need to create another endpoint for login. This endpoint accepts email and password as POST parameters. After receiving the email and password, it checks in database for matched user. If the user is matched, it echoes the success the json response.

7. Create a php file named login.php inside android_login_api with the below content.

6. Under app package create a class named AppConfig.java and add below code. In this class we declare the login and registration urls. While testing you need to replace the ip address with your localhost pc ip.

8. Now open AndroidManifest.xml and add INTERNET permission. Add the AppController class to <application> tag. Also add other activities (LoginActivity, RegisterActivity and MainActivity) which we are going to create shortly. I am keeping LoginActivity as launcher activity as it should be seen on app launch.

9. Under helper package, create a class named SessionManager.java and add below code. This class maintains session data across the app using the SharedPreferences. We store a boolean flag isLoggedIn in shared preferences to check the login status.

10. Under helper package, create a class named SQLiteHandler.java and paste the below code. This class takes care of storing the user data in SQLite database. Whenever we needs to get the logged in user information, we fetch from SQLite instead of making request to server.

Run the app and navigate to register screen by tapping on the link below login button.

4.3 Adding the Home Screen

Until now we are done with both login and registration screen. Now we’ll add the final screen to show the logged in user information. This information will be fetched from SQLite database once user is logged in.

16. Open the MainActivity.java and do below changes. Here we are just fetching the logged user information from SQLite and displaying it on the screen. The logout button will logout the user by clearing the session and deleting the user from SQLite table.

Ravi is hardcore Android programmer and Android programming has been his passion since he compiled his first hello-world program. Solving real problems of Android developers through tutorials has always been interesting part for him.

It only shows when a user is logged in for the first time on second login it doesn’t show up. It’ll be a great help if you can give me your idea about what causes this error

Gemson Gonzales

i already fixed this by adding CONFLICT_REPLACE on insert method. Just in case someone get this error here’s what i did.
you need to import this one:
import static android.database.sqlite.SQLiteDatabase.CONFLICT_REPLACE;
then declare it as int “private static int conflictAlgorithm = CONFLICT_REPLACE;”
and I replaced my insert code with this:
long id = db.insertWithOnConflict(TABLE_USER, null, values, conflictAlgorithm);

Thank you for this example Ravi, great help now I can start with what i want to do

This only shows up on first time log in of the user, on second log in and so on it doesn’t show up anymore. What do you think causes this error? Would be a great help if you can give me your idea about this.

kelvin skip

hello my login is givin a json error and my registration details do not go to the database please help.

You have to understand the code correctly otherwise your life becomes tougher . Try to understand the article and read every line of code.

Death Star

Thanks a ton for the response Ravi. Here it is
[27-Oct-2017 13:41:47 UTC] PHP Warning: require(../scripts/config.inc.php): failed to open stream: No such file or directory in C:wamp64wwwbtcmcxindex.php on line 16

well i have also tried this but nothing happand,stil suffers with {“error”:true,”error_msg”:”Required parameters email or password is missing!”}’, i guess it is not able to get access to the parameters but anyhow i don’t understand this thing

hari

Even I am facing the same issue

trupti

Working on localhost but on server error occur Fatal error: Call to undefined method mysqli_stmt::get_result() in /home/android_login_api/include/DB_Functions.php

Ananda Satriyo

your function.php name see it bro and you will realize, i got confused for a moment too
just rename the fuction.php file and it will resolve your rob

hi, i added more columns to my table “users” and when i register the user it gives me the error ‘unknown error occurred in registration’ but when i remove those columns, it works fine. why am i getting the error?

I followed the entire tutorial but i am struggling to connect using the request code. When i ran the request code in postman i get the same message as above. I get a java.net.connect Exception. I am trying for a long time can u pls help?

Great work Mr.Ravi , It’s successfully but i want to showing all data in database(online) by ListView !?

Merve

Hi,there is a problem.
E/DataScheduler: isDataSchedulerEnabled():false
E/RegisterActivity: Registration Error: null Why and how to solve this?

Merve

in addition ,{“error”:true,”error_msg”:”Required parameters (name, email or password) is missing!”}

Vu Dinh Phong

Why do we use StringRequest? I try to change to JsonObjectRequest but it gave me error, since the json response start with { . Thank you!

Oliver

Dear Ravi,
I compare all codes with yours, all are the same, but when I run app, it crashes! Logcat points to some Null pointer Exception! I think it has problem with sending params in post method .
I checked all things , but I can’t find the problem, please help me ..
thanks.

Hi Ravi,
How import DB in PHPMyAdmin?
When I try to import the error shown below:
#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘use android_api

Hi Ravi
Thanks for the tuto but my problem is that i can’t turn on wifi on my android emulator so i can’t test the app . I tried to install adb wifi plugin but the problem consist… i saw on your demo video that you have used android emulator and not an usb device and i want to do the same thing because i dont have an android smartphone to connect it via usb.. i have iphone…i hope you answer me soon thank you ^_^

Thank you , my emulator is connected via cellular data and not via wireless (i can’t turn it on with the emulator there’s no option in the settings) , i have 0 errors and when i try to test the application and i check my DB i found nothing new so i can’t login , i thought that the problem come from the network because you said that the pc and the emulator must be connected to the same WIFI… i don’t know ! what do you think about this? (PS: im beginner :/ )

hey,
At the time of submitting data to database I’m getting error that “Forbidden, you don’t have permission to access database on this server” I also have tried by changing permissions into httpd.conf but it didn’t work. please help me

Hi Ravi, I have a slightly strange problem. When I try to register on online database. It registers, but doesn’t show the response. When I press The Register Button again it says user already exist, and then I find it in the database. However the Login button doesn’t work. What could be the problem.

im already added loginActivity on my androidmanifest but its still closes

FATAL EXCEPTION: main
Process: com.develop.almaz.ibibi, PID: 4515
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.develop.almaz.ibibi/com.develop.almaz.ibibi.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.develop.almaz.ibibi/com.develop.almaz.ibibi.activity.LoginActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2193)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2243)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5019)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.develop.almaz.ibibi/com.develop.almaz.ibibi.activity.LoginActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1645)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1441)
at android.app.Activity.startActivityForResult(Activity.java:3424)
at android.app.Activity.startActivityForResult(Activity.java:3385)
at android.app.Activity.startActivity(Activity.java:3627)
at android.app.Activity.startActivity(Activity.java:3595)
at com.develop.almaz.ibibi.MainActivity.logoutUser(MainActivity.java:75)
at com.develop.almaz.ibibi.MainActivity.onCreate(MainActivity.java:41)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2157)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2243)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5019)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)

Hi Ravi,
First of all, thank you for all your great tutorials and codes, helped me immensely in various projects..
I have ran into some issues with the Android Login And Registration project..
User registration gets entered into the database (using sql database on web – not local PC),
But when using same details to login, does not work..
Nothing happens and just a small greyish black circle comes up towards the bottom of the screen..
Appreciate any assistance on this..
Thanks

Make sure that both devices (the device running the PHP project and the android device) are on the same wifi network.
how change it ?
while i am trying login it not connect .i want to run php in one wifi network and application in another network
please help me sir

Your both the devices (PC and Mobile) has to be there in the same network (won’t work on LAN again). Once both are connected, your pc ip should be accessible in mobile chrome browser.

Death Star

I have added AppController like this..is this wrong?

Hasan Rahman Sawan

Hi Ravi, I am having an interesting issue. Once I have logged in using one user, i kept on getting into the same user no matter whatever credential I give. On the other hand, when I enter a wrong details right after launching the app, it gives the expected error message. But afterwards it doesnt log me in no matter what. I checked with the API response by returning the email. It kept on returning the same(1st entered) email. Somehow my params are not changing. Any idea?

Hi Ravi, Nice tutorial for beginner. Can you let me know how I can implement one time login in my App using this code? Actually I wanted to implement one time login. User will login once and there is no Logout in my App. I will be wonder if this can be done with this code. Thanks

You can do that using SharedPreferences. Store a boolean values login true in prefs. When the app is launched, check for this value and go to appropriate screen.

Rajeev sah.

thank you so mauch sir,this code is so simple and easy to understand ….can you pls help me…i want to store the user details with there images and once he successfully login the username and image is shown.

Hi there, thanks for your tutorial. I have a question though: “Is this method secure?” if i host my DB on a website so that people can login from around the world then it seems that the “plain” password is sent to server. Is it okay or should i do something about it?

Ammar Nafi Al Abbaz

plz help ravi… i testing for JSON response in POSTMAN and the response is

It’s worked like charm with Localhost using Wamp. I am now uploading all stuff to production server and testing it. But Seems like there is something t=wrong with the PHP codes. I dont know what I am missing. I have tried with postman also. Here is the Postman screenshot. Fun part is register is inserting data but login is not working

The parameters in POST method won’t go in url, they should go in post params. Check on Params button left to send and add your parameters.

Md. Azizul Alam (Toton)

I got the Postman problem. Now I am doing the correct POST method using postman. But the problem is when I am doing the POST method using localhost its returning the values. But when I am trying the same thing using production server its now returning null/blank. Even when I am trying to Login through Apps a Blank Toast is appearing and not going to MainActivity intent. The difference in Header I found, the Localhost is using php 5.3.0 and the Production server is using Php 7.0.24. Dont know why this kind of behavior is happening

hello and thanks for your tutorial. I’m not an expert and i using your
sample in a project. For some reasons, my teamate want to change the
server and the DB for node.js and mongo.db. i’m wondering if you have a
solution to make the same thing without SQLite ?

Michael Keller

Hello everyone, I’m Michael.😊
How do I add a new line by calling the “User Status” database inside a TextView in MainActivity?
I’m try but don’t work anything 🙁

umang mehta

Hi, I am new to android, and tried this code completely with no modification,application get crashed each time by clicking reg button on login button.

tested php code its working great
but android code is not working at all.

I saw the article, but I can not understand. To tell you the truth I do not know how to start. The MainActivity already takes the Name and Email of the logged in user, I just wanted to get one more that would be the Status / Citation.

Is the JSON is proper first of all? If you access the url from Postman, it should echo only plain json not other php errors. Pls check that first.

Anshul Grover

hello sir thanks for your guidance but getting some errors please help me sir….
i added few more values like address,phone etc and make changes everywhere in android php code related to them
W/System.err: org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
also used postman for passing values getting the result below:
{
"error": true,
"error_msg": "Required parameters is missing!"
}
pleaseeeeeeeee help me sir…………

It Works for me, Great tutorial, but how can i write php for forgot password?. Please help.

Falan Abdulla

thanks for the post

unfortunately im getting blank toast while register

can you please help?

prashant maheshwari

i need help, My App is not sending data back to database, when i added some more Fields. the App launches and after filling the fields, when i click register the progress bar just arrives and gone. when i had checked database then nothing is showing there.

You can debug using Try Catch. Try wrapping your php code in try code and see what error was thrown. Alternatively you can enable php error reporting and see the errors along with the json.

prashant maheshwari

thank sir,

Thomas Chateau

Hello Ravi !
First of all, amazing tuto, really clear and helpfull 🙂
I’m just issuing a problem that a lot of people have and I can’t fix it.
It has been a few hours I’m trying to solve it and still, no solution for me. I’ve read all the comments and tried a few things but still the same problem …
So let me explain :
Your code works perfectly but when I’m registering I got a fatal error with the Json parsing.
Catlog error :https://uploads.disquscdn.com/images/e22c9fe703dcb532093be041a1545d7eda1a00cc69c00c7beab5943b070695b8.png
So the problem from what I understood come from the PHP.
The error is :
“{“error”:true,”error_msg”:”Required parameters email or password is missing!”}”
So that means that nothing is sent.
When I’m using Postman, it returns me an error with the line 36 of DB_Functions.php but it looks fine for me…https://uploads.disquscdn.com/images/6d2a3b8062f4290d12223b673cbf00bd92a4233c0150373388a34feec830ad64.png
I hope your answer will help me. I’ve seen you have answered to that kind of question a lot so you must be tired…
Again thanks for this tutorial,
Thomas

Thomas Chateau

By the way, I tried this “solution” :
require_once dirname(__FILE__).
And apparently it’s not from there. Still the same error with the bind_param() function.

Seems some fields are missing from your SQLite table. I can see address column is missing. If you have properly kept the columns names in CREATE statement, try uninstalling the app and install again as newly added columns will be created only on first time app install.

Tulip Dutta

Thank you for your reply. Actually the problem is in the SQLite statement. The SQLite statement is missing a space before the word TEXT.

I first have to thank you for sharing your deep knowledge, to spend your time for creating your tutorials and to support so many people worldwide. Really impressive! I didn’t want to disturb you and so I looked now 1,5 days for a solution to this following debugging challenge … but wasn’t able to find:

In LoginActivity and in RegisterActivity inside checkLogin() and registerUser() we have the onResponse()-Override in which we call a Log

which is keeping also when I restore the .toString() or remove the whole Log – only on new test devices I ‘m able to reproduce the first error, what could mean that Volley is getting an expression that cannot be handled … maybe because of the String definition … ???

I first thought it would be an error in implementing your solution to my existing code, but after exactly rebuilding your solution 1:1 (even with same package name) I have the same result …

In URL_LOGIN and URL_REGISTER I have set my IP (192.168.178.108) which I of course got from ipconfig. I’m running Wampserver64 and used the mySQL-DB, not like with my App-DB which is the MariaDB. I used the standard root login without password like in the phpMyAdmin-login and localhost as host like it is mentioned in the phpMyAdmin welcome-screen.

Is the String definition in:

public void onResponse(String response)

really correct? … or where else could you expect the solution?

It would be fine if you could find some time – if not, thank you as well for your efforts to the whole worldwide developer community.

Best regards
Gerd

Syed Abdul Rahman Wafa

Hi sir,
why I cannot add images using ImageView at activity_login.xml ?
The image is not shown in the emulator.

Hello Mr.Ravi i have tried to check everything even from comments tried, but still i cannot register new user into the database, below is my logcat. and i will comment my DbFunctions.php and Register.php thanks

This is nothing do with mobile phone. It’s the configuration on WAMP software on your computer.

Techlingda Tutorials

I tried your this and it works perfectly.Then I host android_api in a server.After that I make a database which is called carbon12_android_api.But after changing that name It never work register or login
PLEASE HELP ME

I’ve tried on my Samsung Galaxy s7, on the virtual devices of Android Studio ( Nexus 5 and Nexus 5X) and on a Zopo one.
I’m not using Wamp but the IP of my own domain and i’ve tried both http and https!
Thank you for helping me 🙂

Pls spend time on understanding the article and codes. I would like to answer to your queries only tomorrow.

Bijay Luitel

I will do that and will let you know tomorrow, if I can’t come up with an answer. Thank you very much! Also, I have sent you a friend request and a text message on facebook. It would be great, if I can be on your friendlist and can learn many things from you. Thank you very much Ravi!

Bijay Luitel

Registration error: Null, I’m getting this error in cat log.

Bijay Luitel

Please ignore my message. Got the solution.

Bijay Luitel

The issue was because of IP address.

Bijay Luitel

Hi Ravi,

I still couldn’t find the above solution. Are you able to help me please?

Bijay Luitel

Says cannot resolve symbol

Pippy O Lewiso

Hi Ravi, I am receiving this error in the logcat ‘E/MultiWindowProxy: getServiceInstance failed’ then ‘E/RegisterActivity: Registration Error: null’ when i am trying to register

Hey ravi thanks for helping out noobs here 🙂
i created new activities where user entered their blood group and phone with name after logged in .
Android part is quite done i have created sqllitehandler2 with new postReqActivity changed the values but the problem is logcat is giving me error please check the screenshot attached secondly i have added new PHP file for this activity and added link to that on app config and changed the variable on both plus added new function on DB_Func file but my logcat is not happy please check the screenshot , Thanks for help https://uploads.disquscdn.com/images/f8c6a1ad042736a57514432d7597fccc7ceecef4ce6feac9636b4ecc18fe14e4.png

You php code changes are not correct. There is an error. Check the WAMP / MAMP php error logs. Also use Postman to send request and make sure the php endpoint is working correctly. You can enable php error reporting in the code itself to see the errors on the page.

Are you using Postman to test? This uses a POST method which can’t be send via website.

Brian Lun

You can try it with POSTMAN and remember to put your params in Body but not Headers

Brian Lun

You should not perform db.adduser in RegisterActivity. Otherwise if you signup an account and login with another one, the MainActivity will show the previous one. adding user into sqlite in LoginActivity is already enough.

Brian Lun

But this is a very good tutorial indeed. It really helped me. Thank you Ravi.

Hi Ravi, If I need to allow user to store atleast 6 digit password with combination of number and letter and also have them enter only valid email address in order to register then where can I add a code? Please let me know and what code, if you can please,

vips

hii ravi, first of all nice tutorial man,here i just need your help actually i have build every files and folders like yours and i have also made necessary changes like changing the database name, table name where necessary but every time i am trying to access the api by using url it says like ‘{“error”:true,”error_msg”:”Required parameters email or password is missing!”}’ and same with both register and login api and i have also checked the code on postman but the situation remains unchanged and same error is still there ,so please help with it

vips

i enabled mysqli in php.ini file and got it working through postman but still the android part does not seem to be working correctly, actually nothing happens whenever i write credentials on android edittext i think it is not able to connect to local database

The local database can’t be connected via android mobile. For that you need to use ip address of your computer and both the devices has to be in the same wifi network.

What is the url you are using to connected from android?

vips

it is working all fine now as i have uploaded it on real servers

Brian Lun

Hi Ravi, I am actually new to Android Development. I would like to ask you if it is possible to use session manager to store some data that has to be shared to different intent, then I don’t need to pass it via putExtra. Is it possible?

You have PHP errors. Hit the same url from Postman, you can see the php errors there. Try to fix them until you get proper json response. (enable php error reporting if you are not seeing errors in Postman)

Haris Bashir

Help me to solve this problem i see every thing in logcat but problem not solved

Thank
you in advance, I tried your code, and had a bit of trouble on login,
did not display any error on toast, and did not go into MainActivity,
even though all inputs are correct. I have not modified anything in your script. what’s the problem?

Yess Ravi, when I register, everything runs correctly, and the data I input has also entered into the database, but when I login with the correct data, it does not go into MainActivity, and just show the empty toast

Seems AppController is not added to manifest file. Recheck the 8th point.

vips

hello , i need help in login problem of my app ,the scene is like when i tried same code of both php and android and localhost wamp as my server ,it worked all fine but as soon as i posted that same files to actual hostinger servers ,there are some problems, the register however is working and it stores data but the login function does not seem to work whenever i try to login with credentials , there is a error toast as ‘ Value <br of type java.lang.String cannot be converted to JSONObject on android ' , then i searched on internet but not able to solve it fully so please help me…

vips

hello , i need help in login problem of my app ,the scene is like when i tried same code of both php and android and localhost wamp as my server ,it worked all fine but as soon as i posted that same files to actual hostinger servers ,there are some problems, the register however is working and it stores data but the login function does not seem to work whenever i try to login with credentials , there is a error toast as “Value <br of type java.lang.String cannot be converted to JSONObject" , i searched on internet also but with no success..

Jenny Gutiérrez

Why do you use SQLite if you have MYSQL?

Chandu Parmar

Hey Ravi,This works perfectly! Thank you
Registration is working but I have a problem in login
Activity: Login Response:Fatal error: Call to undefined method mysqli_stmt::get_result() in /home/u962968717/public_html/android_login_api/DB_Functions.php on line 64

I’ve tried in several ways how to create a String KEY inside the SQLiteHandler, inside the MainActivity, LoginActivity and RegisterActivity and also inside the DB_Functions to see if I could get some connection, but I can’t. 🙁

Michael Keller

I just need a text from within the users/surname and display in a textview. But I can’t.

Yes, the email and name are working perfectly, but I can not display anything else besides them.

erick jayson deguzman

Sir Ravi Tamada, Wheres my error in my code ?
and how to fix the tools in activity_main.xml tools:context=”${relativePackage}.${activityClass}”
and i dont know how to get value of android to get phpmyadmin

@ravi8x:disqus I’m getting some similar problem, but my login php file it’s just as good as yours .. when I hit it on browser says: ” {“error”:true,”error_msg”:”Required parameters email or password is missing!”} ” I belive it means that it’s working fine … but I’m still getting the ” Value <br of type java.lang.String cannot be converted to JSONObject " error, could you give-me a hand ? I'll give you my email if u have a little time to explain to me : igor.comp.ufla@outlook.com. by the way , thank you for the tutorial, very cleaver ! =)

The name, email, password should be posted in Body tab instead of Headers. Check once again.

erick jayson deguzman

i want to attach my program to my phone, and url is still the same 10.0.2.2?

Isat Mos

What the happen?
*********************
Error:Unsupported method: BaseConfig.getApplicationIdSuffix().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.
*********************
Help me! Thank you

Whats the problem with mysql insertion. Explain the scenario / code would be useful.

Praful Dhabekar

Hi again, I resolved the issue. The problem was with my WiFi Firewall setting I had to turn it off . Thanks for you response and for your tutorial also. Maybe it’s too much to ask but do you have any tutorial on Filter JSON Data in Android Application using PHP and MySQL?

Yeah figuring out the Wifi problem is tricky always, it’s good that you figured it out. I haven’t done any filtering article as of now. You can just create an endpoint and write the php logic to search by LIKE statement in mysql and return the response. If the data is very less (below 100 rows), you can use client side filtering to show the same.

Hello Sir, this code runs fine in case I store in localhost..but when I store in hostinger server then I get the following error :
Call to undefined method mysqli_stmt::get_result()
Please help me getting me out of this..

Check the php error logs or use Postman to make call to same url to see the php errors.

Vishist Varugeese

Hello Ravi Sir.
I am new to android development. From what I have read on Google, SQLite is a database that is server-less and is locally available in Android. So in this article”Android Login and Registration with PHP, MySQL and SQLite” is it okay if i skip the SQLite part? What would be the drawbacks of doing so? Please help me clarify my doubt.

We used SQLite here just to cache / offline data. Let’s say you want to display some profile information like email, name, address etc., we can store this info SQlite, so that even if there is no internet connection we can show the data. Otherwise we need to fetch this information by making call to server everytime. It’s completely upto you whether to consider it or not.

Erickson Teixeira

Hi Sir
Please help me
I followed your steps and the app returns this message: json error value <br of type java lang string cannot be converted to json object
Could you guide me?

Nice to see that you are still responding regarding this. I am having issues with this as I’ve spent a few days trying to figure out what I’m missing. I’ve created the application, added the table to phpmyadmin and also know my ip address for my computer that I’m trying to use as the server. The issue I’m having is sending the response to the phpmyadmin as when I try to register a circular toast icon appears with no words and doesn’t add users to the table. I’m also not sure where I’m supposed to put the JSON responses? Also in both the Register and Login activity I am getting an error at public void onResponse onErrorResponse and StringRequest saying that the class doesn’t override its superclass. I’m not entirely new at development but don’t understand the php mysql stuff yet and need to learn it by the new year.
Thank you if you responde

First of all, you need to make sure that the JSON endpoints are working fine. For this use Postman client to test the URLs and make sure the JSON response is proper. Once that is done, the URLs should be accessible via mobile. The mobile and PC should be on the same network. Open the same URL directly in the mobile browser to see whether it’s accessible via wifi network.

Please post your complete error log for further debuggin.

Thanks for your appreciation 🙂

Jdn90

Hello Ravi,

I have checked into this and downloaded Postman. What I get when I load the URL in Postman is the following {“error”:true,”error_msg”:”Required parameters email or password is missing!”}–{“error”:true,”error_msg”:”Required parameters (name, email or password) is missing!”}– If this is correct than I’m definitely doing something wrong with being able to access the URL’s from my device. When I load them via Chrome on my computer they show the same message, but when I load the URL from my phone same WiFi (I did follow steps) it won’t grab the information.

I have tried everything possible to access other devices on my network with both the routers I have plus even my range extender. I’ve also even hard wired my computers and tried accessing other computers from both routers separate and still not able to access the files unless on the main computer running postman. So I’m unsure as to what is happening here.

1. What your localhost URL and the URL with your PC IP address you are trying to open in the mobile browser?

2. If the problem still persists, you can get another spare mobile and create a hotspot. Connect your mobile and PC to this hotspot and try. (Creating the hotspot from the same mobile on which you are trying the app won’t work)

Anand Vb

This is a great tutorial, very much helpful.
Hi, i like to dig deep into android, can you help me out?. How to connect with you?

Hello. Thanks for the great tutorial. I have successfully built the apk file. I tested it in my mobile phone and I faced a problem. Whenever I entered all the information and then clicked the button of login or register, the application will be terminated immediately. I even don’t know what the problem is. Do you have any idea what problem I am facing and how to solve it. Thank you!

Connect your phone to your PC via USB cable and install the app from Android Studio. You can see the errors in LogCat of Android Studio when the app is crashed.

King

Thank you very much! It seem like the error is “01-04 02:25:39.096 417-417/? E/Parcel: Reading a NULL string not supported here.”
However, I have entered the required information to the fields.
What is the problem? (cry)

Hi Ravi, I am using your code for my login signup but when i run the program its shows data successful enter but in my server there is no data and when i login from that username its shows. please provide me your mail id so i can mail you my problem

Kunal

This error i got this from this code (“Value null of type org.json.JSONObject$1 cannot be converted to JSONObject”) in this specific line showing the error JSONObject jObj = new JSONObject(response);
and
StringRequest strReq = new StringRequest(Request.Method.POST,
AppConfig.URL_REGISTER, new Response.Listener() {

It will be generated automatically once the project is built. It has to match with your package name.

Bob

I have completed the application but I have one question. How to enable the action bar? When I completed the project, the action bar of the application is disappeared in my phone but I can still see the action bar in the design of layout file. I want to enable the action bar. Thank you.

When I added an additional action bar, it give me an error like:This Activity already has an action bar supplied by the……
In fact, I can see my action bar in the layout.xml file. However, when I executed the application, the action bar was disappeared. I compared the manifest file of this application to the newly created application. They do not contain a big difference but the newly created application contain the action bar. I really wonder how I can make the action bar appear again.

Hello. I already copied your code exactly both in Android (Android Studio) and PHP (Netbeans), as well as the database (I’m using XAMPP). Everytime I finish filling-up the registration form, all the data that I inputted in the registration form were not being stored at the localhost.

This is the error in my php:
{“error”:true,”error_msg”:”Required parameters (name, email, or password) is missing!”}

Thank you!

Cedie

This is the output everytime I finish filling-up the registration form:

Your PHP project working fine on your localhost machine. The error of missing parameters find as the url should be accessed by POST method. As you are opening it in browser, it makes GET request. Thats why you are seeing missing params error. Consider hitting the same url from Postman with POST method and proper params. You will see the correct results.

When you are trying it on mobile, the ip address you are replacing should be accessible in mobile chrome browser. If it’s not working, you need to play with your modem configuration to make it work.

i have an issue when after login/failed login i logout and relogin keeps the login info from the first time example
i log with user abc and pass xyz and login well then i logout and try to login with user def and pass wer and still logs like user abc? this alsdo happens if the fisrt time login credtians are wrong i cant login

Hi brother, I need an App like this but some other feature will be added. Please tell me how do you can help me. By developing? Or by referring a trusted Developer?
Mail: limon.jfl@gmail.com
Wapp: +8801745656549

Hi ravi, I followed your article, and when i try to test it (the register) I get the following error:http://prntscr.com/i6ckcy
I’ve entered all the variables and changed it to POST, so it should get into the registration, but instead it fails getting them.
Any idea why it could happen?
I’m pretty new to this WAMP server thing, this would really help me, thanks in advance <3

Ori Zehavi

@ravi8x:disqus I really cant make that work, would really appreciate some help

i am having issue with the registration code after i have upload it to digitalocean Ubuntu server pls help me out
this is the error
({“error”:true,”error_msg”:”Unknown error occurred in registration!”})

Okay. Normally there would be php / mysql errors when you are deploying services on server. It’s because of may few extensions might not enable in php. To see the errors you need to open the error logs on the server and see the errors.

For example, if the server I am using is Nginx, the error logs can be at /var/log/nginx/errors.log. If you open this file via terminal / FTP you can see the errors. By going through the errors and searching for the solution, you can fix them. Once they are fixed, your app runs smoothly.

i got this error:
Error:Unsupported method: BaseConfig.getApplicationIdSuffix().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.

the program doesn’t call volley in so both
RegisterActivity and LoginActivity
are having errors

Could you try the register endpoint and check whether details are getting stored in db or not?

Jamal Jalloh

Hi Ravi,

First of all I’d like to say thank you for responding means a lot, I tried the register endpoint (after adding the necessary function to the update user script) and got that same error …. {“error”:true,”error_msg”:”Required parameters (name, email, password, gender or age) is missing!”}… I have attached screenshots below….

I realised something a lot more weird which may be of help, I modified my login script by adding:

echo ($_REQUEST[’email’]);
echo ($_REQUEST[‘password’]);

AND THE PARAMETERS ARE OUTPUTTED, really confused as to what’s going on… maybe a workaround would be to set:

I see an awesome job you have done there. Don’t worry that really depends on the server config. Sometimes they ignore $_POST methods / headers etc., This article is just to give you an idea. Once you understood the flow, you can go for a good framework to build the same services like Slim (micro framework), Laravel etc.,

// Check if user is already logged in or not
if (session.isLoggedIn()) {
// User is already logged in. Take him to main activity
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
}

The url is not accessible via app. You can open the url in Browser and Postman and check what is happening. Most probably the ip address is incorrect / changed.

Victor Cabeza Cifuentes

Hi Ravi, now I got this when i try login or registration (photo) i assume that from my mobile the app can’t do registration and login because the php scripts are in my laptop, do you think that i can put those php scripts in some cloud database like Firebase and then access to them from my laptop or my mobile, and if this is posible i suppose that i must change the URL_LOGIN and URL_REGISTER from AppConfig.java , what do you think?

You can see register.php, DB_connect.php garbage printed along with JSON. Go through all files and comment those line. I think those lines left somewhere in the PHP and they are getting printed along with JSON.

I am getting 500 Server Error. I have hosted it on A2Hosting Server. When I am trying to login through Postman it also returning 500 Server Error. In another question someone got the same problem, but his problem solved by changing the Volley library. I am not understanding what is the relation between Volley library and this error. I am using Google Volley Library rather than Maxioke. When using in App. the Toast returning Blank both for login and register but wondering that the registering row is inserting in the table.