Volley error PHP Android Studio, not recognizing the POST

Asked

Viewed 43 times

0

I’m having problems with the connector or Android. I really don’t know. I already use Volley in other activities but had never given this problem. Can anyone help me in this? Returns who did not recognize the elements within the POST, as if had not gotten there what came out of Android.

loads the list of players coming from the bank, and chooses one of them, and loads the chosen element of the spinner from the list of actions (e.g., wrong pass), and the URL used, declared in the global:

String url_monta_graf_jogador = "http://192.168.15.17/pizza_acoes_jogador.php";

loadSpinnerJogadores(url_busca_jogadores);
    spinnerJogadores.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (parent.getItemAtPosition(position).equals("Escolha o jogador:")) {
                //faz nada
            } else {
                jogador = spinnerJogadores.getItemAtPosition(spinnerJogadores.getSelectedItemPosition()).toString();
                escolherJogador(acao, jogador);
            }
        }
        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

the method that sends both data to the database, and where the problem occurs:

public void escolherJogador(final String nomeAcao, final String nomeJogador){
    Toast.makeText(Graficos.this, nomeAcao+" "+nomeJogador, Toast.LENGTH_SHORT).show();
    RequestQueue queue = Volley.newRequestQueue(Graficos.this);
    StringRequest stringRequest = new StringRequest(Request.Method.POST, url_monta_graf_jogador, new Response.Listener<String>() {
        @Override
        public void onResponse(String resposta) {
        }
    },new Response.ErrorListener(){
        @Override
        public void onErrorResponse (VolleyError error){
            Toast.makeText(Graficos.this, "Erro no servidor", Toast.LENGTH_SHORT).show();
            error.printStackTrace();
        }
    }){
        @Override
        protected Map<String, String> getParams () {
            Map<String, String> params = new HashMap<String, String>();
            params.put("acao", nomeAcao);
            params.put("jogador", nomeJogador);
            return params;
        }
    };
    queue.add(stringRequest);
}

in PHP: the file is called pizza_acoes_gamer.php because the return will be a graph

 <?php 
  require_once("conexao.php");

  $nomeAcao = $_POST['acao'];
  $nomeJogador = $_POST['jogador'];
...
?>

The famous "Notice: Undefined index: action/player in error..."

inserir a descrição da imagem aqui

I would even do it by button, so there’s a strange button there, but it will be owing the same parameters, no use pushing the problem.

  • That one notice indicates that the Index you are searching for does not exist, in the case of the action => $_POST['acao'] and gambler => $_POST['jogador']

  • 1

    That I know, but I’m passing them here: params.put("action", nomination); params.put("player", gamename). Wouldn’t that be some mistake in Java? Help me, Please!

  • 1

    Check if the function getParams this being called, put a Log.d("getParams", "PASSOU AKI"), inside it, maybe before the return to also show the var params. I advise you to do this in other places to trace the path that your Volley should be doing.

  • 1

    This proposal of yours helped to find the solution, even if "table". I checked here and found the error. There was a webview that was called from outside. This webview receives, on another page, as require (obviously you have to receive for the graph to be mounted) the page where you have the Posts. Then he understands that he is calling again those Posts, which appears as empty. I moved the chart mount to the same page where you receive the Posts gave no more problem when calling the webview. Thank you very much!!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.