X

Android Login And Registration based on MYSQL Database using php Part 1.

 

Android Login and Registration MySQL :

This tutorial will help you to learn how to make Android Login and Registration MYSQL database using php.

Every app requires login which sometimes may be essential in app performance as app must have an entry only for authorized person.

 

For Second part of tutorial visit : Login And Registration based on MYSQL Database using php Part 2

 

 

Creating MYSQL Database :

 

This tutorial on Android Login and Registration MySQL will help you to learn how to make Login and Registration based on MYSQL database using php.

Every app requires login which sometimes may be essential in app performance as app must have an entry only for authorized person.

 

 

Creating MYSQL Database :

 

create table users(
   id int(10) primary key auto_increment,
   name varchar(30) not null,
   username varchar(30) not null,
   password varchar(30) not null  
);

 

 

Creating PHP File for Connecting to Database

We need to connect to database by using parameters like

Hostname, Username, Password, DBName

 

connect.php

Creating a php connect file for Android Login and Registration MySQL.

<?php

 define('Hostname','localhost'); //db host
 define('Username','root'); // db username
 define('Password',''); //db password
 define('DBName','user'); // db name

 $con = mysqli_connect(Hostname,Username,Password,DBName) or die('Cannot Connect');

 ?>

 

Creating php file for Registration

 

While registration user need to provide details like name, username, password and these details will be saved in the database and will be verified in further steps.

 

 

register.php

 

<?php

require_once('connect.php');

$name = $_POST['name'];
$username = $_POST['username'];
$password = $_POST['password'];

$sql = "insert into users (name, username, password ) 
                         values ('$name','$username','$password')";

$res = mysqli_query($con,$sql);

$check = mysqli_fetch_array($res);

if(isset($check)){
echo 'success';
}else{
echo 'failure';
}

mysqli_close($con);
?>

 

 

Creating php file for Login

 

At the time of login we need to check whether the user credentials are available in our database or not if available then should be verified and then access is to be given.

 

login.php

 

<?php

require_once('connect.php');

$username = $_POST['username'];
$password = $_POST['password'];

$sql = "select * from user where username='$username' and password='$password'";

$res = mysqli_query($con,$sql);

$check = mysqli_fetch_array($res);

if(isset($check)){
echo 'success';
}else{
echo 'failure';
}

mysqli_close($con);

 

 

 

Now our MYSQL database is created and using these php files we can connect to server, register and perform login.

 

In out next tutorial we will see how to code in android using this database and files.

 

For Second part of tutorial visit : Login And Registration based on MYSQL Database using php Part 2

 

If you have any query’s in this tutorial on Android Login and Registration MySQL do let us know in comment section below.

If you like this tutorial do like and share us for more interesting tutorials.

 

abhishek:
Related Post

This website uses cookies.