0

I'm working on an application that registers users in a database of a domain I have. I developed it using Android Studio, and I'm having some problems handling the users info to the php file using the POST method.

The main problem I have is that my app returns a success while transfering the data to the database, but when I look at it it's empty.

Here's my Java code:

package com.test.application;

import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;

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

public class RegisterRequest extends StringRequest {

private static final String REGISTER_REQUEST_URL="http://www.mywebsite.com/Register.php";
private Map<String,String> params;
public RegisterRequest(String user, String password, String email, Response.Listener<String> listener){
    super(Method.POST, REGISTER_REQUEST_URL, listener, null);
    params = new HashMap<>();
    params.put("name", user);
    params.put("password", password);
    params.put("useremail", email);
}

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

and here's my PHP code that recieves the data:

<?php
    $con = mysqli_connect("bbdd.mywebsite.com", "user", "password", "database");
    
    $Username = $_POST["name"];
    $Password = $_POST["password"];
    $UserEmail = $_POST["useremail"];
    $statement = mysqli_prepare($con, "INSERT INTO AccountsInfo (Username, Password, UserEmail) VALUES (?, ?, ?)");
    mysqli_stmt_bind_param($statement, "ssis", $Username, $Password, $UserEmail);
    mysqli_stmt_execute($statement);
    
    $response = array();
    $response["success"] = true;  
    
    echo json_encode($response);
?>
4
  • 2
    What exactly is the problem you are having? Commented Dec 3, 2018 at 18:13
  • The problem I'm having is that it returns me back a success in transfering the data in the php code but when I look at the database it's empty Commented Dec 3, 2018 at 18:14
  • 1
    You may want to modify your question to tell us what the problem actually is. That said, that connection string looks pretty suspicious. Since you never check for errors you'll never know whether or not it failed. Try localhost instead of bbdd.mywebsite.com and see what happens. Oh and turn on error reporting while you are doing development. ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); Commented Dec 3, 2018 at 18:19
  • okay, thanks about that Commented Dec 3, 2018 at 18:22

1 Answer 1

1

Assuming everything else is correct, your parameter type specification in the bind call has an i (integer) that doesn't match any parameter. For 3 string parameters, you'll want to use sss:

mysqli_stmt_bind_param($statement, "sss", $Username, $Password, $UserEmail);

You should enable error reporting so that things don't just fail silently. See how to get a detailed error report when a php-mysql script fails?

Sign up to request clarification or add additional context in comments.

1 Comment

Oh true! I added it by mistake. Everything alright now. Thanks a lot ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.