title: How to fetch data from mysql in android using retrofit
body: <p>actually i want to fetch the data from mysql using retrofit in android. This is my scenario
  I am passing a string data from one activity to another which is fine now i want to use this variable to select the same data in database for e.g my string has a value of 2 now i want see in database wether the same 2 is in db or not like it some kind of seacrhing.</p>
  
  <p>Here is mysql code</p>
  
  <pre><code>
  &lt;?php
      $servername="localhost";
      $username="root";
      $password="";
      $dbname="academia";
  
  $conn=mysqli_connect($servername,$username,$password,$dbname);
  error_reporting(0);
  $connDB= mysqli_select_db($conn,'academia');
  if ($_SERVER['REQUEST_METHOD']=='POST') {
     $mobile = $_POST['Mobile_Number'];
      $sql = "SELECT Mobile_Number FROM school_signup WHERE Mobile_Number='$mobile' ";
  
      $response = mysqli_query($conn, $sql);
  
      $data = mysqli_num_rows($response);
      if($data&gt;0)
  {
          $error='ok';
  
          echo json_encode(array('response'=&gt;$error,'Mobile_Number'=&gt;$mobile));
  
  }else{
  $error = 'failed';
  echo json_encode(array('response'=&gt;$error));    
  }
  }
  
  ?&gt;
  </code></pre>
  
  <p>Now here is the code of Apinterface.java</p>
  
  <pre><code>import retrofit2.Call;
  import retrofit2.http.Field;
  import retrofit2.http.FormUrlEncoded;
  import retrofit2.http.POST;
  import retrofit2.http.Query;
  
  public interface Apinterface {
     // @FormUrlEncoded
      @POST("login.php")
  
      Call&lt;MobileNumber&gt; sendnum(@Query("Mobile_Number") String Mobile_Number);
  
  }
  
  </code></pre>
  
  <p>Now here is code of ApiClient.java</p>
  
  <pre><code>import retrofit2.Retrofit;
  import retrofit2.converter.gson.GsonConverterFactory;
  
  public class ApiClient {
      private static final String BASE_URL = "http://192.168.10.4/android_register_login/";
      private static Retrofit retrofit;
      private static ApiClient mInstance;
  
      public static Retrofit getApiClient() {
  
              retrofit = new Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).build();
  
          return retrofit;
      }
  
  }
  
  </code></pre>
  
  <p>Here is file to initialize variables</p>
  
  <pre><code>
  public class MobileNumber {
  
      @SerializedName("response")
      @Expose
      private String response;
      @SerializedName("Mobile_Number")
      @Expose
      private String mobileNumber;
  
      public String getResponse() {
          return response;
      }
  
      public void setResponse(String response) {
          this.response = response;
      }
  
      public String getMobileNumber() {
          return mobileNumber;
      }
  
      public void setMobileNumber(String mobileNumber) {
          this.mobileNumber = mobileNumber;
      }
  
  }
  </code></pre>
  
  <p>Here is my mainactivity file</p>
  
  <pre><code>    protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_school_mobile_code);
          apiInterface = ApiClient.getApiClient().create(Apinterface.class);
  }
   private void sendnum(){
          Bundle bundle = getIntent().getExtras();
          final String Mobile_Number= bundle.getString("Mobile");
          Call&lt;MobileNumber&gt; call =apiInterface.sendnum(Mobile_Number);
          call.enqueue(new Callback&lt;MobileNumber&gt;() {
              @Override
              public void onResponse(Call&lt;MobileNumber&gt; call, Response&lt;MobileNumber&gt; response) {
                  if(response.body().getResponse().equals("ok")){
                      Toast.makeText(SchoolMobileCode.this, "Success", Toast.LENGTH_SHORT).show();
  
                  }
                  else if(response.body().getResponse().equals("failed")){
                      Toast.makeText(SchoolMobileCode.this, "Error", Toast.LENGTH_SHORT).show();
  
                  }
              }
              @Override
              public void onFailure(Call&lt;MobileNumber&gt; call, Throwable t) {
                  //display errror message
                  Toast.makeText(SchoolMobileCode.this, "F"+t.getMessage(), Toast.LENGTH_SHORT).show();
              }
          });
  
      }
  
  </code></pre>
  
  <p>One thing more response coming from json is absloutly fine the problem is in "Mobile_Number" variable which i am send to to do same search</p>