Error making request without refresh in database

Asked

Viewed 23 times

0

Guys, I’m making a system that when searching the name of an access in the search field, it searches in the database some word referring to what the user wrote in the input... I followed a youtube tutorial to do because what I wanted.

Javascript code at the end of index.php

                <form method="post">
                    <div class="input-field col s12 l12">
                        <input id="pesquisa" name="pesquisa" type="text">
                        <label for="pesquisa">Pesquisar Acesso...</label>
                    </div>
                </form>

<script>
    $("#pesquisa").keyup(function(){
    var busca = $("#pesquisa").val();

    $.post('pesquisaAcesso.php', {busca: busca},function(data){
      $("#result").html(data);
    });
  });

</script>

Code of the searchAccess.php

Pastebin.com/Fnji0tlx

placed in Pastebin because here the code . php is not indented

Anyway, when I try to search the name of the access in the field, it returns me the following error. It is not taking the data passed via post, if I modify the variable for an access you have in the bank, it searches normal, but in $_POST it does not take the value that is placed in the input. inserir a descrição da imagem aqui

  • 1

    Change $_POST['pesquisa'] for $_POST['busca']

  • It worked!!!!!!!!!! thanks man, but why the exchange of $_POST['search'] for $_POST['search'] ?? the $_POST it pulls from the var search, right ?

  • Exactly, you defined the field as quest: {busca: busca} and used research.

  • By the way, obviously, you can do the opposite, change the name quest for research in your javascript. The question was not to rename a field, but to use what was passed by JS.

  • 1

    Got it! thanks guys. I’m going to study javascript because I don’t know anything yet. I follow a tutorial on youtube to do this. Thanks!!!

No answers

Browser other questions tagged

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