User registration page not verified

<?php
    	
       

    $name = $_POST["name"];
    $age = $_POST["age"];
    $email = $_POST["email"];
    $password =$_POST["password"];

    $statement = mysqli_prepare($db, "INSERT INTO user_info(name,age,email,password) 
    VALUES
    (?,?,?,?)");  
    mysqli_stmt_bind_param($statement, "siss", $name, $age, $email, $password);
    mysqli_stmt_execute($statement);
     
      if($statement>0){
               $response["success"] = 1;
             }    
         else{
               $response["success"] = 0;
             }
        
         echo json_encode($response);



    ?>
Run code

My user registration page does not want to check. Please advise which side of the encoding between the PHP text file and the android side will validate. Please help further, here is the code.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

final EditText Name = (EditText) findViewById(R.id.edtName);
final EditText Age = (EditText) findViewById(R.id.edtAge);
final EditText Email = (EditText) findViewById(R.id.edtUsername);
final EditText Password = (EditText) findViewById(R.id.edtPassword);
final ImageButton validate = (ImageButton) findViewById(R.id.btnReg);

validate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final int age = Integer.parseInt(Age.getText().toString());
final String name = Name.getText().toString();
final String email = Email.getText().toString();
final String password = Password.getText().toString();


Name.setText("");
Age.setText("");
Email.setText("");
Password.setText("");

                                                                         Response.Listener<String>responseListener=new                                    Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if (success) {
Intent intent = new Intent(Register.this, Login.class);
Register.this.startActivity(intent);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(Register.this);
builder.setMessage("Register Failed")
.setNegativeButton("Retry", null)
.create()
.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
RegisterRequest registerRequest = new RegisterRequest(name, age, email,  password, responseListener);
RequestQueue queue = Volley.newRequestQueue(Register.this);
queue.add(registerRequest);
}
});
}

public void extBtn(View view) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
}
+4
source share
1 answer

Try using this part of your code:

$bind = mysqli_stmt_bind_param($statement, "siss", $name, $age, $email, $password);
$execute = $bind->mysqli_stmt_execute($bind);

 if(count($execute) > 0){
     $response["success"] = 1;
 } else{
     $response["success"] = 0;
 }       

 echo json_encode($response);

count - counting the rows in your database.

0
source

Source: https://habr.com/ru/post/1659011/


All Articles