title: How to stop the process if name exists in the database android
body: <p>I have one page by this page new user can register in my app to his can use my app.<br />
  I have two fields in this page one for phone number and second for his password.<br />
  Also I have one button if his press this button his will move to another page.</p>
  <p>What I try to do I need in this page if user click this button to continue to another page before move I try to check if this phone number or his ID of device in my db already. So if his phone number or ID devices already exists in my db. user will show message like &quot;phone number already available&quot; and stop continue to another page or stop this process. In this case button of continue will be not work. That what I try to do.</p>
  <p>Now the code in button like that:</p>
  <pre><code>        findViewById(R.id.buttonContinue).setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  String code = CountryData.countryAreaCodes[spinner.getSelectedItemPosition()];
                  if (number.isEmpty() || number.length() &lt; 6) {
                      editText.setError(&quot;Valid number is required&quot;);
                      editText.requestFocus();
                      return;
                  }
  
                  String phoneNumber = &quot;+&quot; + code + number;
                  String UserCountry = spinner.getSelectedItem().toString();
                  Intent intent = new Intent(RegistrationPage.this, VerifyPhoneActivity.class);
                  intent.putExtra(&quot;phonenumber&quot;,phoneNumber);
                  intent.putExtra(&quot;phone&quot;, &quot;+&quot;+code+ phone);
                  startActivity(intent);
  
              }
          });
  
  </code></pre>
  <p>how I try to do it like that. I make one connection by volley and php file to see if this phone number available in db or no.</p>
  <pre><code>private void Regist(){
          String URL_REGIST = &quot;https://xxxxxxxxxxxxx/registers.php&quot;;
          StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_REGIST,
                  new Response.Listener&lt;String&gt;() {
                      @Override
                      public void onResponse(String response) {
                          try {
                              JSONObject jsonObject = new JSONObject(response);
                              String Response = jsonObject.getString(&quot;response&quot;);
                              Toast.makeText(RegistrationPage.this,&quot;Test&quot;+ Response, Toast.LENGTH_LONG).show();
  
  
  
                          } catch (JSONException e) {
                              e.printStackTrace();
                         Toast.makeText(RegistrationPage.this,&quot;This device already exists&quot;, Toast.LENGTH_LONG).show();
                          }
  
                      }
                  }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                          Toast.makeText(RegistrationPage.this, &quot;Register Error! &quot; + error.toString(), Toast.LENGTH_SHORT).show();
  
                      }
                  })
  
          {
              @Override
              protected Map&lt;String, String&gt; getParams() throws AuthFailureError {
                  Map&lt;String, String&gt; params = new HashMap&lt;&gt;();
                  params.put(&quot;deviceID&quot;,deviceID);
  
                  return params;
              }
          };
  
          RequestQueue requestQueue = Volley.newRequestQueue(this);
          requestQueue.add(stringRequest);
  
  
      }
  
  </code></pre>
  <p>And add this method in button before intent:</p>
  <pre><code>        findViewById(R.id.buttonContinue).setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
  Regist();//================here like that 
  
  
                  String code = CountryData.countryAreaCodes[spinner.getSelectedItemPosition()];
                  if (number.isEmpty() || number.length() &lt; 6) {
                      editText.setError(&quot;Valid number is required&quot;);
                      editText.requestFocus();
                      return;
                  }
  
                  String phoneNumber = &quot;+&quot; + code + number;
                  String UserCountry = spinner.getSelectedItem().toString();
                  Intent intent = new Intent(RegistrationPage.this, VerifyPhoneActivity.class);
                  intent.putExtra(&quot;phonenumber&quot;,phoneNumber);
                  intent.putExtra(&quot;phone&quot;, &quot;+&quot;+code+ phone);
                  startActivity(intent);
  
              }
          });
  
  </code></pre>
  <p>Now like that my code is working I can see message of &quot;This device already exists&quot;. But still the user move to another page so how I can make it stop if this message come?</p>
  <p>PHP CODE</p>
  <pre><code>&lt;?php
      include 'connt.php';
  $deviceID = $_POST['deviceID'];
  
   $CheckSQL = &quot;SELECT * FROM user WHERE deviceID='$deviceID'&quot;;
   
   $check = mysqli_fetch_array(mysqli_query($con,$CheckSQL));
   
   if(isset($check)){
  
   echo 'phone Already Exist';
  
   }
          mysqli_close($con);
      
      
  ?&gt;
  
  </code></pre>