Samuel Samuel - 3 years ago 131
MySQL Question

why is username registered as null in database?

I am currently working on an android app and I completed a register and login form for android.

The only Problem is that the username is always declared as a 0.

I hope you can understand me and can help me too!

MySql output

php code:


android-studio code:

public class RegisterActivity extends AppCompatActivity {

protected void onCreate(Bundle savedInstanceState) {

final EditText etAge = (EditText) findViewById(;
final EditText etName = (EditText) findViewById(;
final EditText etUsername = (EditText) findViewById(;
final EditText etPassword = (EditText) findViewById(;

final Button bRegister = (Button) findViewById(;

bRegister.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final String name = etName.getText().toString();
final String username = etUsername.getText().toString();
final int age = Integer.parseInt(etAge.getText().toString());
final String password = etPassword.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(RegisterActivity.this, LoginActivity.class);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
builder.setMessage("Register Failed")
.setNegativeButton("Retry", null)
} catch (JSONException e) {

RegisterRequest registerRequest = new RegisterRequest(name, username, age, password, responseListener);
RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);


Answer Source

You are binding the username as an integer value.

mysqli_stmt_bind_param($statement, "siss", $name, $username, $age, $password);

My assumption is you want to bind your $age an interger value instead?

Try changing the above to this:

mysqli_stmt_bind_param($statement, "ssis", $name, $username, $age, $password);

Hope this helps!

EDIT: Hopefully you are just testing and will implement this but you NEED to be hashing your passwords!

Please look into this:

And start using the password_hash() and password_verify() functions as part of your login/registration scripts.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download