Introduction
Open Wampserver on your browser by writing localhost or localhost:8080. In your browser, a page will be displayed.

Click on "PhPmyadmin" on the left side.





- <?php
- /**
- * A class file to connect to database
- */
- class DB_CONNECT
- {
- // constructor
- function __construct()
- {
- // connecting to database
- $this->connect();
- }
- // destructor
- function __destruct()
- {
- // closing db connection
- $this->close();
- }
- /**
- * Function to connect with database
- */
- function connect()
- {
- // import database connection variables
- require_once __DIR__ . '/db_config.php';
- // Connecting to mysql database
- $con = mysql_connect(DB_SERVER, DB_USER, DB_WORD) or die(mysql_error());
- // Selecing database
- $db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());
- // returing connection cursor
- return $con;
- }
- /**
- * Function to close db connection
- */
- function close()
- {
- // closing db connection
- mysql_close();
- }
- }
- ?>
db_config.php
- <?php
- /*
- * All database connection variables
- */
- define('DB_USER', "root"); // db user
- define('DB_WORD', ""); // db word (mention your db word here)
- define('DB_DATABASE', "employee"); // database name
- define('DB_SERVER', "localhost"); // db server
- ?>
Create a PHP file to store information on the server.
Step 8
Create an XML file and write this. In this XML file, you will use two text views, two edittexts, and a button.
- <?php
- /*
- * Following code will create a new product row
- * All product details are read from HTTP Post Request
- */
- // array for JSON response
- $response = array();
- // check for required fields
- if (isset($_POST['id']) && isset($_POST['name'])) {
- $id = $_POST['id'];
- $name = $_POST['name'];
- // include db connect class
- require_once __DIR__ . '/db_connect.php';
- // connecting to db
- $db = new DB_CONNECT();
- // mysql inserting a new row
- $result = mysql_query("INSERT INTO employe_data(id, name) VALUES('$id', '$name')");
- // check if row inserted or not
- if ($result) {
- // successfully inserted into database
- $response["success"] = 1;
- $response["message"] = "Product successfully created.";
- // echoing JSON response
- echo json_encode($response);
- } else {
- // failed to insert row
- $response["success"] = 0;
- $response["message"] = "Oops! An error occurred.";
- // echoing JSON response
- echo json_encode($response);
- }
- } else {
- // required field is missing
- $response["success"] = 0;
- $response["message"] = "Required field(s) is missing";
- // echoing JSON response
- echo json_encode($response);
- }
- ?>
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
- <!-- Name Label -->
- <TextView android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Employee_Id"
- android:paddingLeft="10dip"
- android:paddingRight="10dip"
- android:paddingTop="10dip"
- android:textSize="17dip"/>
- <!-- Input Name -->
- <EditText android:id="@+id/inputId"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_margin="5dip"
- android:layout_marginBottom="15dip"
- android:singleLine="true"/>
- <!-- Price Label -->
- <TextView android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Employee_Name"
- android:paddingLeft="10dip"
- android:paddingRight="10dip"
- android:paddingTop="10dip"
- android:textSize="17dip"/>
- <!-- Input Price -->
- <EditText android:id="@+id/inputName"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_margin="5dip"
- android:layout_marginBottom="15dip"
- android:singleLine="true"
- />
- <!-- Description Label -->
- <!-- Button Create Product -->
- <Button android:id="@+id/btnCreateProduct"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Create "/>
- </LinearLayout>



Angus CameronPosted Dec 16, 2020, 4:37 AM
Amir, this is a very helpful article but there is some detail I would like please, eg the field names you have created or the SQL query. Also the names of all the php files and the xml file. Finally the location of the php files. Thanks
Safdar IqbalPosted Feb 16, 2017, 2:04 PM
You are using xamp server , but i have make windows form .net application , then how can i make connection?