I am trying to make a basic register/login application in Android Studio. I am using php and a web server. I have two php files, Register.php and Login.php so I want to register a user and store the entered information in the mysql server. When I enter the information in the android app and press register button I get this error :
JSONException: Value <html><body><script of type java.lang.String cannot be converted to JSONObject
so here is my register.php file
<?php
$con = mysqli_connect("raps.byethost7.com", "****", "****", "****");
$name = $_POST["name"];
$last_name = $_POST["last_name"];
$e_mail = $_POST["e_mail"];
$password = $_POST["password"];
$statement = mysqli_prepare($con, "INSERT INTO user (name, last_name, e_mail, password) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($statement, "siss", $name, $last_name, $e_mail, $password);
mysqli_stmt_execute($statement);
$response = array();
$response["success"] = true;
echo json_encode($response);
?>
and here is the java file of the activity:
public class SignupActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
final EditText ETname = (EditText) findViewById(R.id.name);
final EditText ETlast_name = (EditText) findViewById(R.id.last_name);
final EditText ETe_mail = (EditText) findViewById(R.id.e_mail);
final EditText ETpassword = (EditText) findViewById(R.id.password);
final Button bSignup = (Button) findViewById(R.id.signupButton);
bSignup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String name = ETname.getText().toString();
final String last_name = ETlast_name.getText().toString();
final String e_mail = ETe_mail.getText().toString();
final String password = ETpassword.getText().toString();
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(SignupActivity.this,LoginActivity.class);
SignupActivity.this.startActivity(intent);
}
else {
AlertDialog.Builder builder = new AlertDialog.Builder(SignupActivity.this);
builder.setMessage("Register Failed!").
setNegativeButton("Retry",null).create().show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
RegisterRequest registerRequest = new RegisterRequest(name,last_name,e_mail, password,responseListener );
RequestQueue queue = Volley.newRequestQueue(SignupActivity.this);
queue.add(registerRequest);
}
});
}
}
I have been working on this for hours so please help me.