I have one page by this page new user can register in my app to his can use my app.
I have two fields in this page one for phone number and second for his password.
Also I have one button if his press this button his will move to another page.
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 "phone number already available" 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.
Now the code in button like that:
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() < 6) {
editText.setError("Valid number is required");
editText.requestFocus();
return;
}
String phoneNumber = "+" + code + number;
String UserCountry = spinner.getSelectedItem().toString();
Intent intent = new Intent(RegistrationPage.this, VerifyPhoneActivity.class);
intent.putExtra("phonenumber",phoneNumber);
intent.putExtra("phone", "+"+code+ phone);
startActivity(intent);
}
});
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.
private void Regist(){
String URL_REGIST = "https://xxxxxxxxxxxxx/registers.php";
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_REGIST,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
String Response = jsonObject.getString("response");
Toast.makeText(RegistrationPage.this,"Test"+ Response, Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(RegistrationPage.this,"This device already exists", Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(RegistrationPage.this, "Register Error! " + error.toString(), Toast.LENGTH_SHORT).show();
}
})
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("deviceID",deviceID);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
And add this method in button before intent:
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() < 6) {
editText.setError("Valid number is required");
editText.requestFocus();
return;
}
String phoneNumber = "+" + code + number;
String UserCountry = spinner.getSelectedItem().toString();
Intent intent = new Intent(RegistrationPage.this, VerifyPhoneActivity.class);
intent.putExtra("phonenumber",phoneNumber);
intent.putExtra("phone", "+"+code+ phone);
startActivity(intent);
}
});
Now like that my code is working I can see message of "This device already exists". But still the user move to another page so how I can make it stop if this message come?
PHP CODE
<?php
include 'connt.php';
$deviceID = $_POST['deviceID'];
$CheckSQL = "SELECT * FROM user WHERE deviceID='$deviceID'";
$check = mysqli_fetch_array(mysqli_query($con,$CheckSQL));
if(isset($check)){
echo 'phone Already Exist';
}
mysqli_close($con);
?>