Search Filter for some reason is not looking for the product

Asked

Viewed 26 times

-3

<?php include ('conecta.php'); ?>

<table width="753" height="191" border="0">
  <tr align="center" valign="middle">
    <td bgcolor='#FFFFCC' colspan='5' valign="middle" width="72"><a href="carrinho.php"><img src="imagens/carrinho.png" border='0' width="50" height="50" />  </a></td>

    <td width="123" valign="middle" bgcolor="#FFFFCC">Buscar</td>
    <td width="167" height="50" valign="middle" bgcolor="#FFFFCC"><label for="buscar"></label>
      <input type="text" name="buscar" id="buscar" /></td>
    <td width="103" valign="middle" bgcolor="#FFFFCC"><input type="submit" name="Aceitar" id="Aceitar" value="Buscar" /></td>

  </tr>
  <tr align="center" valign="middle" bgcolor="#000000">
    <td colspan="8" bgcolor="#000000" class="cor">LISTA DE PRODUTOS</td>
  </tr>
  <tr align="center" valign="middle" bgcolor="#ff9966">
    <td>ID</td>
    <td>IMAGEM</td>
    <td>NOME</td>
    <td>DESCRIÇÃO</td>
    <td>PREÇO</td>
    <td>QUANTIDADE</td>
    <td>DATA</td>
    <td>ADICIONAR</td>
  </tr>

  <?php 
  $consulta = mysql_query("SELECT * FROM produtos");

  if (isset($_POST['buscar'])){
    $consulta = mysql_query("SELECT * FROM produtos where nome like '%".$_POST['buscar']."%'"); 
  }

  while($linha = mysql_fetch_array($consulta)) {

    $id = $linha['id'];
    $imagem = $linha['imagem'];
    $nome = $linha['nome'];
    $desc = $linha['descricao'];
    $preco = $linha['preco'];
    $quant = $linha['quantidade'];
    $data = $linha['data'];
    //$adicionar = '<a href="carrinho.php?id='.$linha['id'].'"title="'.$linha['id'].'"> Adicionar </a>'
  ?> 

  <tr align="center" valign="middle" bgcolor="#FFFFCC">
    <td><?php echo $id; ?></td>
    <td><img src="<?php echo $imagem; ?>" width="70" height="70"></td>
    <td><?php echo $nome; ?></td>
    <td><?php echo $desc; ?></td>
    <td><?php echo $preco; ?></td>
    <td><?php echo $quant; ?></td>
    <td><?php echo $data; ?></td>
    <td>
      <form action="carrinho.php" method="post" name="comprar">
        <input name="id_txt" type="hidden" value="<?php echo $id; ?>" />
        <input name="nome" type="hidden" value="<?php echo $nome; ?>" />
        <input name="preco" type="hidden" value="<?php echo $preco; ?>" />
        <input name="quantidade" type="hidden" value="1" />
        <input name="Comprar" type="submit" value="Comprar" />
      </form>
    </td>
  </tr>

  <?php } ?>

</table>
  • 1

    What’s wrong with the code? What’s your question? Without you talking, there’s no way to guess.

  • 2

    First problem is using functions mysql_*. They are obsolete in PHP 5 and have already been removed from PHP 7.

1 answer

1

To work the input fields must be inside the tag form

<form action="" method="POST" >
<input type="text" name="buscar" id="buscar" /><input type="submit" name="Aceitar" id="Aceitar" value="Buscar" />
</form>

Browser other questions tagged

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