This tutorial deals with the PHP integrating MYSQL database to insert a values using api and this api is called from android app.

Before going any further let us know the basic operations we can perform like CRUD operations

1) Create

2) Read

3) Update

4) Delete


So let’s get started now


Step 1:


This is first step of connecting to the database here we provide the details required


  1.  Hostname is the place where the database is.
  2.  Username for the user access.
  3.  Password  is required for maintaining security for local host this will be empty.
  4.  DBName  this will select the database out of all your databases present on your server


And can be defined as


and finally using all these values we will try to connect with server to establish a connection first leter on we can perform fetch, insert, update or delete.



Step 2:


The first step in insert.php is to connect to a server so


And then accept the values thus coming from api and save them in local variables

here the local variables are  –> $name , $age, $phone, $email



Now run the MYSQL query for inserting the values



Now lets query with the help of connect class and the query written above


then after processing it will return success or failure and again this will have many barriers to be passed like

  1. Database should exists
  2. Table should be created and
  3. Field name should be matched exactly


check condition to finalize the result using a array (array may not be required)


then a if else condition to validate result


Step 3:

At last close the connection i am mentioning this as a step because its important to do so and good practice too.




Share like and subscribe if you like this tutorial

For more detailed explanation view the video tutorial below.






Show Buttons
Hide Buttons
Read previous post:
Android Kotlin Tutorial on Operators