title: Sending data from android studio app to server
body: <p>I am trying to send data from my android studio app to mysql php server and here is my code, the program can run but my server cannot receive data from my app. Did I make a mistake somewhere in my coding?</p>
  
  <p>My android studio app coding</p>
  
  <pre><code>package com.sp.toilert;
  
  import android.app.PendingIntent;
  import android.bluetooth.BluetoothAdapter;
  import android.content.Context;
  import android.content.Intent;
  import android.content.IntentFilter;
  import android.nfc.NdefMessage;
  import android.nfc.NdefRecord;
  import android.nfc.NfcAdapter;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.os.Parcelable;
  import android.support.v7.app.AppCompatActivity;
  import android.util.Log;
  import android.view.View;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import org.apache.http.HttpResponse;
  import org.apache.http.NameValuePair;
  import org.apache.http.client.ClientProtocolException;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.entity.UrlEncodedFormEntity;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.message.BasicNameValuePair;
  
  import java.io.IOException;
  import java.io.UnsupportedEncodingException;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Calendar;
  import java.util.List;
  
  
  public class MainActivity extends AppCompatActivity {
  
  NfcAdapter nfcAdapter;
  TextView txtTagContent;
  private BluetoothAdapter myBluetooth = null;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(com.sp.toilert.R.layout.activity_main);
  
      checkBTState();
      nfcAdapter = NfcAdapter.getDefaultAdapter(this);
      txtTagContent = (TextView) findViewById(R.id.txtTagContent);
  
  }
  
  public void buttonOnClick(View v) {
  
  new SubmitData().execute();  //do something when button clicked  
  
  }
  
  public class SubmitData extends AsyncTask&lt;String, String, String&gt; {
  
      @Override
      protected String doInBackground(String... strings) {
  
          try {
  
              postData();
  
          } catch (NullPointerException e) {
              e.printStackTrace();
          } catch (Exception e) {
              e.printStackTrace();
          }
          return null;
      }
  
      //this function is the main thing that will upload the data to the server
      public void postData() {
          // Create a new HttpClient and Post Header
          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost("http://172.22.47.245/notthatdirty.php");
  
          try {
              // these are all the fields that will be submitted
              List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);
              //nameValuePairs.add(new BasicNameValuePair("MyName","MyValue"));
              nameValuePairs.add(new BasicNameValuePair("cubicle_ID", "100003")); //send data to server
              nameValuePairs.add(new BasicNameValuePair("issue", "dirty")); //send data to server
              httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  
              // Execute HTTP Post Request
              HttpResponse response = httpclient.execute(httppost);
  
          } catch (ClientProtocolException e) {
              // TODO Auto-generated catch block
          } catch (IOException e) {
              // TODO Auto-generated catch block
          }
      }
  }
  </code></pre>
  
  <p>My server coding</p>
  
  <pre><code>&lt;h1&gt;WELCOME TO TOILERT&lt;/h1&gt;&lt;/P&gt;
  
  &lt;?php
  $servername = "localhost";
  $username = "toilert";
  $password = "toilert";
  $dbname = "cleaning_db";
  
  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  
  // Check connection
  if ($conn-&gt;connect_error) {
  die("Connection failed: " . $conn-&gt;connect_error);
  }
  echo "Connected successfully";
  
  //http://localhost/toilet-backend/backend.php?dirty=1&amp;cubicleID=10003
  //GET the data from android
  /*
  $dirty = $_GET["dirty"]; //1 for true . 0 for false
  $emergency = $_GET["emergency"]; //1 for true . 0 for false
  $faulty = $_GET["faulty"]; //1 for true . 0 for false
  */
  
  $issue = htmlspecialchars($_GET["issue"]); // Sanitize input with         htmlspecialchars
  $cubicleID = $_GET['cubicleID'];
  
  //Check if the request has been sent before
  //ensure no duplicate toilet data
  $query = "SELECT * FROM cleaner_request WHERE cubicle_id = $cubicleID";
  $result = $conn-&gt;query($query);
  
  if ($result-&gt;num_rows &gt; 0) {
  $json = array("status" =&gt; 200, "msg" =&gt; "Complaint has already been         created");
  echo json_encode($json);
  } else {
  switch ($issue) {
      case "dirty":
      case "emergency":
      case "faulty":
          $query = "INSERT INTO cleaner_request (cubicle_id, $issue) VALUES     ('$cubicleID', '1')";
          break;
      default:
          $error = "Invalid status";
  }
  if (empty($error)) {
      $result = $conn-&gt;query($query);
      echo "Data written to Database";
      $json = array("status" =&gt; 200, "msg" =&gt; "Complaint has been successfully  created");
      } else {
      echo "error" ;
      //$json = array("status" =&gt; 418, "msg" =&gt; $error);
  
  }
  echo json_encode($json);
  /* Ben commented this out. Because code
  if ($dirty == 1) {  //dirty
      $query = "INSERT INTO cleaner_request (cubicle_id,dirty) VALUES    ('$cubicleID','$dirty')";
      $result = $conn-&gt;query($query);
      $json = array("status" =&gt; 200, "msg" =&gt; "Complaint has been successfully  created");
      echo json_encode($json);
      } else if ($dirty == 0) { //clean
  
      }
     */
      //check require location
      require 'C:/xampp/htdocs/toilet-backend/twilio-php-master/Services/Twilio.php';
   $AccountSid = "AC52a80f076cca00c9547fdfd17bf4fbbb";
   $AuthToken = "b145c2d4f7b722fe79cbe38f3009afcc";
  
   // Step 3: instantiate a new Twilio Rest Client
  $client = new Services_Twilio($AccountSid, $AuthToken);
  $client-&gt;account-&gt;messages-&gt;create(array(
      'To' =&gt; "+65 9067 9919",
      'From' =&gt; "+15672420325",
      'Body' =&gt; "Greetings, please clean up Cubicle 100 001 and 100 004. Thank you. This service is brought to you by Toilert.",
  ));
  mysqli_close($conn);  //$conn-&gt;close();
  }
  ?&gt; 
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/Uuq9U.jpg" rel="nofollow">A picture of the server side</a></p>