Search filter for some reason you are not looking for the product.

-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>
    
asked by anonymous 18.03.2017 / 15:03

1 answer

1

To work the input fields must be inside the form tag

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