Android mySQL registration fails with no error.

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 1

Mar 30, 2017, 7:14:25 PM via Website

I'm a student and I'm trying to insert data into mySql database using android. I created the layout, java class as well as php file for registration. I get no errors when I run the app but once I click Sign up Button, it does not work. No error is shown but it does not continue either.
NOTE: I think it is something wrong with my php file. But I might be wrong too.

Here are my codes.

package com.example.mohamedwisam.regtest;

import android.content.Intent; import; import; import android.os.Bundle;
import android.view.View; import android.widget.Button; import
android.widget.EditText; import android.widget.Toast;

import; import; import; import;

import org.json.JSONException; import org.json.JSONObject;

public class Register extends AppCompatActivity {
EditText etName, etPwd, etFullname, etDob;
Button btnReg;

protected void onCreate(Bundle savedInstanceState) {

    etName = (EditText)findViewById(;
    etPwd = (EditText)findViewById(;
    etFullname = (EditText)findViewById(;
    etDob = (EditText)findViewById(;

    btnReg = (Button)findViewById(;

    btnReg.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {

            final String uname = etName.getText().toString();
            final String pwd = etPwd.getText().toString();
            final String fullname = etFullname.getText().toString();
            final String dob = etDob.getText().toString();

            Response.Listener<String> responseListener = new Response.Listener<String>() {
                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);
                        }else {
                            Toast.makeText(Register.this, "ERROR", Toast.LENGTH_LONG).show();

                    } catch (JSONException e) {

            RegisterRequest registerRequest = new RegisterRequest(uname, pwd, fullname, dob, responseListener);
            RequestQueue queue = Volley.newRequestQueue(Register.this);

} }

And Here is my

package com.example.mohamedwisam.regtest;

import; import;

import java.util.HashMap; import java.util.Map;

/** * Created by mohamedwisam on 3/30/17. */

public class RegisterRequest extends StringRequest {
private static final String REGISTER_REQUEST_URL = "url is here. forum does not let me post it yet";
private Map params;

public RegisterRequest(String uname, String password, String name, String dob, Response.Listener<String> listener) {
    super(Method.POST, REGISTER_REQUEST_URL, listener, null);
    params = new HashMap<>();
    params.put("username", uname);
    params.put("password", password);
    params.put("name", name);
    params.put("dob", dob);


public Map<String, String> getParams() {
    return params;
} }

and my PHP file. Reg.php

$con = mysqli_connect("localhost", "root", "", "medicap");

$name = $_POST["username"];
$age = $_POST["password"];
$username = $_POST["name"];
$password = $_POST["dob"];

$statement = mysqli_prepare($con, "INSERT INTO users (username, password, name, dob) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($statement, 'ssss', $name, $username, $age, $password);

$response = array();
$response["success"] = true;

echo json_encode($response); ?>