Login Service In PHP And MySQL For Android Applications – Info PHP
Generally a service is one type of intermediary for communication between multiple different technologies, so here we will make a service which is used to log in valid users to Android applications.
Here the process flow is, the Android app user enters their username and password to the application then presses the login button; now on the login button we call PHP service which connects the My SQL database and checks the user table, and returns a response to the Android application.
For creating the Service in PHP we have to make one page in PHP and also make a table “tbl_User” for storing user data in My SQL, so by using the service we compare the user data coming from the Android app with tbl_User and return the result. For creating a service follow the below steps.
- Make Table in MySQL for storing the user. Give it the name “tbl_User” — this table contains UserName, Password etc; For creating a table run the below script.
- CREATE TABLE IF NOT EXISTS `tbl_user` (
- `ur_Id` int(11) NOT NULL AUTO_INCREMENT,
- `ur_username` varchar(50) NOT NULL,
- `ur_password` varchar(50) NOT NULL,
- `ur_status` int(11) NOT NULL,
- PRIMARY KEY (`ur_Id`)
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
By running the above script it will create a table like below. Here table contains Id, Username, Password, Status etc, columns.
- Now insert some temporary data to this table, so for inserting data in a temporary table I run the below SQL script.
- INSERT INTO `tbl_user` (`ur_Id`, `ur_username`, `ur_password`, `ur_status`) VALUES
- (1, ‘nirav@gmail.com’, ‘nirav’, 1),
- (2, ‘kapil@gmail.com’, ‘kapil’, 1),
- (3, ‘arvind@gmail.com’, ‘arvind’, 1);
After running the below script you will see a table something like below.
- Now we make a PHP service, so create one PHP file and give it the name “service_userlogin.php”.
Thanks for reading my article; if you have any question regarding this than you can ask me in the comment section.
Article Prepared by Ollala Corp