Mysql search with input error

Asked

Viewed 31 times

0

Search ta returning a news and ta returning all the names of the database:

"Notice: Undefined index: search_name" in the.php connection.

if(isset($_POST["acao"])){
    if($_POST["acao"] == "pesquisar_nome"){
        pesquisarCliente();
    }
}

/* Pesquisar Cliente*/
function pesquisarCliente(){
    $bd = new mysqli("localhost", "root", "", "projeto_ap2");    
    $pesquisaNome = $_POST['pesquisar_nome'];
    $sqlPesquisarNome = "SELECT nome FROM cliente WHERE nome LIKE '%$pesquisaNome%'";
    $resultado = $bd->query($sqlPesquisarNome);

    while($rows = mysqli_fetch_array($resultado)){
        echo "Nomes relacionados: ".$rows['nome']."</br>";
    }
}

On the search form:

<form action="../conexao.php" method="POST">        
        <tbody>
            <tr>
                <td>Pesquisar:</td>
                <td><input type="text" name="nomeCliente" value="" placeholder="Digite um nome..."/></td>
            </tr>

            <tr>
                <td><input type="hidden" name="acao" value="pesquisar_nome" /></td>
                <td><input type="submit" value="Pesquisar" name="Pesquisar" /></td>
            </tr>        
        </tbody>
</form></br></br>

2 answers

0

Are you trying to get the input name "search name":

$pesquisaNome = $_POST['pesquisar_nome'];

The name you are passing is "client name"

0

Hello,

Your problem is on the following line:

$pesquisaNome = $_POST['pesquisar_nome'];

There is no input whose name is pesquisar_nome, the solution is to switch to nomeCliente, which is the name of the text input that will receive the name of the client. Try modifying the line in question to:

$pesquisaNome = $_POST['nomeCliente'];



I hope I helped, hug!

Browser other questions tagged

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