Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Andre Rak

[Resolvido] Erro na BUSCA!

Recommended Posts

Ola,

preciso de ajuda em um código de busca em php mysql!

tem um form de busca:

com tres campos: vendedor, mes e ano.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="100%" border="0" cellpadding="0" cellspacing=" 0">
  <tr>
    <td width="15"><div align="center" class="style13 style13"><img src="Imagens/cadeado.gif" alt="" width="30" height="30" /></div></td>
    <td class="style7 style13 style13"><strong><b><strong>Free Travel Turismo</strong></b> - <b><b><a href="fechar.php">Fechar Janela</a></b></b></strong></td>
  </tr>
  <tr>
    <td> </td>
    <td><form id="form1" name="form1" method="get" action="resultado_busca_os8.php">
      <table width="332" border="0">
        <tr>
          <td width="178" class="style7 style13 style13">VENDEDOR:</td>
          <td width="144"><div align="right"> <span class="style7 style13 style13">
            <input type="text" name="vendedor" id="vendedor" />
          </span></div></td>
        </tr>
        <tr>
          <td> </td>
          <td> </td>
        </tr>
      </table>
      <table width="332" border="0">
        <tr>
          <td width="178" class="style7 style13 style13">MES:</td>
          <td width="144"><div align="right"> <span class="style7 style13 style13">
            <input type="text" name="mes" id="mes" />
          </span></div></td>
        </tr>
        <tr>
          <td> </td>
          <td> </td>
        </tr>
      </table>
      <table width="332" border="0">
        <tr>
          <td width="178" class="style7 style13 style13">ANO:</td>
            <td width="144"><div align="right">
              <span class="style7 style13 style13">
                <input type="text" name="ano" id="ano" />
            </span></div></td>
          </tr>
        <tr>
          <td> </td>
            <td><div align="right">
              <span class="style7 style13 style13">
                <input type="submit" name="button" id="button" value="Buscar" />
              </span></div></td>
          </tr>
        </table>
    </form></td>
  </tr>
</table>
</body>
</html>

e a pagina de resultado:

<?php
include "config.php"; //conexão mysql
$exec = mysql_query("SELECT * FROM os WHERE vendedor LIKE '%$vendedor%' OR mes LIKE '%$mes%' OR ano LIKE '%$ano%'") or die("<script>alert('ERRO! Não foi possível conectar ao banco de dados.');location.href='javascript:history.go(-1)';</script>");
$total = mysql_num_rows($exec);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Relatório de OS</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<img src="Imagens/FreeTravelBrazilLogo.png" width="200" height="69" />
<table width="100%" border="0" cellpadding="0" cellspacing=" 0">
  <tr>
    <td width="15"><div align="center"><img src="Imagens/7513_32x32.png" width="32" height="32" /></div></td>
    <td><strong>Free Travel Turismo: Relatório de OS : <?php echo $row_Recordset1['vendedor']; ?>, <?php echo $row_Recordset1['mes']; ?>, <?php echo $row_Recordset1['ano']; ?></strong></td>
  </tr>
  <tr>
    <td> </td>
    <td><table width="100%" border="0" align="center">
      <tr bgcolor="#0099FF">
        <td bgcolor="#99FF00">OS N°</td>
        <td bgcolor="#99FF00">Reserva N°</td>
        <td bgcolor="#99FF00">Funcionario</td>
        <td bgcolor="#99FF00">Mes Lançado</td>
        <td bgcolor="#99FF00">Ano Lançado</td>
        <td bgcolor="#99FF00">Pax</td>
        <td bgcolor="#99FF00">Serviço</td>
        <td bgcolor="#99FF00">Motorista</td>
        <td bgcolor="#99FF00">Guia</td>
        <td bgcolor="#99FF00">Vendedor</td>
        <td bgcolor="#99FF00">Valor</td>
      </tr>
      <?php do { ?>
      <tr>
        <td><?php echo $row_Recordset1['codigo']; ?></td>
        <td><?php echo $row_Recordset1['codigo2']; ?></td>
        <td><?php echo $row_Recordset1['funcionario']; ?>  </td>
        <td><?php echo $row_Recordset1['mes']; ?>  </td>
        <td><?php echo $row_Recordset1['ano']; ?></td>
        <td><?php echo $row_Recordset1['pax']; ?>  </td>
        <td><?php echo $row_Recordset1['servico']; ?>  </td>
        <td><?php echo $row_Recordset1['motorista']; ?>  </td>
        <td><?php echo $row_Recordset1['guia']; ?>  </td>
        <td><?php echo $row_Recordset1['vendedor']; ?>  </td>
        <td><?php echo $row_Recordset1['valor_total']; ?>  </td>
      </tr>
      <?php } while ($row_Recordset1 = mysql_fetch_assoc($exec)); ?>
    </table></td>
  </tr>
</table>
<table width="54" border="0" align="right">
  <tr>
    <td><a href="#" onclick="window.print();"><img src="Imagens/Print_48.png" alt="ASD" width="48" height="48" border="0" /></a></td>
  </tr>
</table>
</p>
<a href="busca_os8.php" class="style19">Fazer nova busca</a>
</body>
</html>

o resultado aparece, porem nao FILTRADA!

aparece todos os resultados!

 

se alguem puder me ajudar! agradeço!

Compartilhar este post


Link para o post
Compartilhar em outros sites

cara, você ta com globals ON ?

 

por que voce manda o formulario por get, e eu nao vi nenhum momento que voce recebe o valor das variaveis.

 

reparou isso ?

Compartilhar este post


Link para o post
Compartilhar em outros sites

seria isso?

 

$vendedor = $_POST["vendedor"];
$mes = $_POST["mes"];  
$ano = $_POST["ano"];  

nao, pq la no <form method=get> no seu form ta METHOD=GET entao seria $_GET['mes'];

 

Mas eu te aconselho a ir la no form e colocar METHOD=POST... ai vai funcionar..

Compartilhar este post


Link para o post
Compartilhar em outros sites

 

ainda nao deu certo!

aparece todos os resultados encontrados!

 

posta seu codigo novamente , para ver como ficou!

 

busca.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="100%" border="0" cellpadding="0" cellspacing=" 0">
  <tr>
    <td width="15"><div align="center" class="style13 style13"><img src="Imagens/cadeado.gif" alt="" width="30" height="30" /></div></td>
    <td class="style7 style13 style13"><strong><b><strong>Free Travel Turismo</strong></b> - <b><b><a href="fechar.php">Fechar Janela</a></b></b></strong></td>
  </tr>
  <tr>
    <td> </td>
    <td><form method="post" id="form1" name="form1" action="resultado_busca_os8.php">
      <table width="332" border="0">
        <tr>
          <td width="178" class="style7 style13 style13">VENDEDOR:</td>
          <td width="144"><div align="right"> <span class="style7 style13 style13">
            <input type="text" name="vendedor" id="vendedor" />
          </span></div></td>
        </tr>
        <tr>
          <td> </td>
          <td> </td>
        </tr>
      </table>
      <table width="332" border="0">
        <tr>
          <td width="178" class="style7 style13 style13">MES:</td>
          <td width="144"><div align="right"> <span class="style7 style13 style13">
            <input type="text" name="mes" id="mes" />
          </span></div></td>
        </tr>
        <tr>
          <td> </td>
          <td> </td>
        </tr>
      </table>
      <table width="332" border="0">
        <tr>
          <td width="178" class="style7 style13 style13">ANO:</td>
            <td width="144"><div align="right">
              <span class="style7 style13 style13">
                <input type="text" name="ano" id="ano" />
            </span></div></td>
          </tr>
        <tr>
          <td> </td>
            <td><div align="right">
              <span class="style7 style13 style13">
                <input type="submit" name="button" id="button" value="Buscar" />
              </span></div></td>
          </tr>
        </table>
    </form></td>
  </tr>
</table>
</body>
</html>

resultado.php:

<?php
include "config.php"; //conexão mysql

$vendedor = $_POST["vendedor"];
$mes = $_POST["mes"];  
$ano = $_POST["ano"];  

$exec = mysql_query("SELECT * FROM os WHERE vendedor LIKE '%$vendedor%' OR mes LIKE '%$mes%' OR ano LIKE '%$ano%'") or die("<script>alert('ERRO! Não foi possível conectar ao banco de dados.');location.href='javascript:history.go(-1)';</script>");
$total = mysql_num_rows($exec);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Relatório de OS</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<img src="Imagens/FreeTravelBrazilLogo.png" width="200" height="69" />
<table width="100%" border="0" cellpadding="0" cellspacing=" 0">
  <tr>
    <td width="15"><div align="center"><img src="Imagens/7513_32x32.png" width="32" height="32" /></div></td>
    <td><strong>Free Travel Turismo: Relatório de OS : <?php echo $row_Recordset1['vendedor']; ?>, <?php echo $row_Recordset1['mes']; ?>, <?php echo $row_Recordset1['ano']; ?></strong></td>
  </tr>
  <tr>
    <td> </td>
    <td><table width="100%" border="0" align="center">
      <tr bgcolor="#0099FF">
        <td bgcolor="#99FF00">OS N°</td>
        <td bgcolor="#99FF00">Reserva N°</td>
        <td bgcolor="#99FF00">Funcionario</td>
        <td bgcolor="#99FF00">Mes Lançado</td>
        <td bgcolor="#99FF00">Ano Lançado</td>
        <td bgcolor="#99FF00">Pax</td>
        <td bgcolor="#99FF00">Serviço</td>
        <td bgcolor="#99FF00">Motorista</td>
        <td bgcolor="#99FF00">Guia</td>
        <td bgcolor="#99FF00">Vendedor</td>
        <td bgcolor="#99FF00">Valor</td>
      </tr>
      <?php do { ?>
      <tr>
        <td><?php echo $row_Recordset1['codigo']; ?></td>
        <td><?php echo $row_Recordset1['codigo2']; ?></td>
        <td><?php echo $row_Recordset1['funcionario']; ?>  </td>
        <td><?php echo $row_Recordset1['mes']; ?>  </td>
        <td><?php echo $row_Recordset1['ano']; ?></td>
        <td><?php echo $row_Recordset1['pax']; ?>  </td>
        <td><?php echo $row_Recordset1['servico']; ?>  </td>
        <td><?php echo $row_Recordset1['motorista']; ?>  </td>
        <td><?php echo $row_Recordset1['guia']; ?>  </td>
        <td><?php echo $row_Recordset1['vendedor']; ?>  </td>
        <td><?php echo $row_Recordset1['valor_total']; ?>  </td>
      </tr>
      <?php } while ($row_Recordset1 = mysql_fetch_assoc($exec)); ?>
    </table></td>
  </tr>
</table>
<table width="54" border="0" align="right">
  <tr>
    <td><a href="#" onclick="window.print();"><img src="Imagens/Print_48.png" alt="ASD" width="48" height="48" border="0" /></a></td>
  </tr>
</table>
</p>
<a href="busca_os8.php" class="style19">Fazer nova busca</a>
</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

cara, os campos Mes e Ano , sao campos INT ?

 

se for, testa esse codigo, dei uma alterada

 

ps : outra coisa, esse arquivo é o resultado_busca_os8.php ou o resultado.php ?

 

<?php
include "config.php"; //conexão mysql

$vendedor = $_POST["vendedor"];
$mes = $_POST["mes"];  
$ano = $_POST["ano"];  

$exec = mysql_query("SELECT * FROM os WHERE (vendedor LIKE '%".$vendedor."%' OR mes LIKE '%".$mes."%' OR ano LIKE '%".$ano."%')") or die("<script>alert('ERRO! Não foi possível conectar ao banco de dados.');location.href='javascript:history.go(-1)';</script>");
$total = mysql_num_rows($exec);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Relatório de OS</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<img src="Imagens/FreeTravelBrazilLogo.png" width="200" height="69" />
<table width="100%" border="0" cellpadding="0" cellspacing=" 0">
  <tr>
    <td width="15"><div align="center"><img src="Imagens/7513_32x32.png" width="32" height="32" /></div></td>
    <td><strong>Free Travel Turismo: Relatório de OS : <?php echo $row_Recordset1['vendedor']; ?>, <?php echo $row_Recordset1['mes']; ?>, <?php echo $row_Recordset1['ano']; ?></strong></td>
  </tr>
  <tr>
    <td> </td>
    <td><table width="100%" border="0" align="center">
      <tr bgcolor="#0099FF">
        <td bgcolor="#99FF00">OS N°</td>
        <td bgcolor="#99FF00">Reserva N°</td>
        <td bgcolor="#99FF00">Funcionario</td>
        <td bgcolor="#99FF00">Mes Lançado</td>
        <td bgcolor="#99FF00">Ano Lançado</td>
        <td bgcolor="#99FF00">Pax</td>
        <td bgcolor="#99FF00">Serviço</td>
        <td bgcolor="#99FF00">Motorista</td>
        <td bgcolor="#99FF00">Guia</td>
        <td bgcolor="#99FF00">Vendedor</td>
        <td bgcolor="#99FF00">Valor</td>
      </tr>
      <?php while ($row_Recordset1 = mysql_fetch_array($exec)) { ?>
      <tr>
        <td><?php echo $row_Recordset1['codigo']; ?></td>
        <td><?php echo $row_Recordset1['codigo2']; ?></td>
        <td><?php echo $row_Recordset1['funcionario']; ?>  </td>
        <td><?php echo $row_Recordset1['mes']; ?>  </td>
        <td><?php echo $row_Recordset1['ano']; ?></td>
        <td><?php echo $row_Recordset1['pax']; ?>  </td>
        <td><?php echo $row_Recordset1['servico']; ?>  </td>
        <td><?php echo $row_Recordset1['motorista']; ?>  </td>
        <td><?php echo $row_Recordset1['guia']; ?>  </td>
        <td><?php echo $row_Recordset1['vendedor']; ?>  </td>
        <td><?php echo $row_Recordset1['valor_total']; ?>  </td>
      </tr>
      <?php }  ?>
    </table></td>
  </tr>
</table>
<table width="54" border="0" align="right">
  <tr>
    <td><a href="#" onclick="window.print();"><img src="Imagens/Print_48.png" alt="ASD" width="48" height="48" border="0" /></a></td>
  </tr>
</table>
</p>
<a href="busca_os8.php" class="style19">Fazer nova busca</a>
</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

cara, voce ta fazendo alguma coisa errada, nao é possivel , olhei rapido , pq to indo embora, vou para casa agora, de la eu olho... mas aparentemente ta tudo certo cara.. abraços!

Compartilhar este post


Link para o post
Compartilhar em outros sites

cara, ja tentei de tudo! na da certo! :(

 

beleza cara! vo fica tentando! quando puder ajudar de novo! agradeço.

 

Solução para o problema proposto é que a SINTAXE SQL está incorreta, Aó invés de utilizar OR tem que ser AND.

 

;)

Compartilhar este post


Link para o post
Compartilhar em outros sites

 

cara, ja tentei de tudo! na da certo! :(

 

beleza cara! vo fica tentando! quando puder ajudar de novo! agradeço.

 

Solução para o problema proposto é que a SINTAXE SQL está incorreta, Aó invés de utilizar OR tem que ser AND.

 

;)

 

Vlw pia! UAEHUAHEUAHEUAHEUAHEUHAEUHAEHUAEHUAE

isso ai mesmo! tava errado a SINTAXE SQL!

 

codigo correto:

busca.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="100%" border="0" cellpadding="0" cellspacing=" 0">
  <tr>
    <td width="15"><div align="center" class="style13 style13"><img src="Imagens/cadeado.gif" alt="" width="30" height="30" /></div></td>
    <td class="style7 style13 style13"><strong><b><strong>Free Travel Turismo</strong></b> - <b><b><a href="fechar.php">Fechar Janela</a></b></b></strong></td>
  </tr>
  <tr>
    <td> </td>
    <td><form method="post" id="form1" name="form1" action="resultado_busca_os8.php">
      <table width="332" border="0">
        <tr>
          <td width="178" class="style7 style13 style13">VENDEDOR:</td>
          <td width="144"><div align="right"> <span class="style7 style13 style13">
            <input type="text" name="vendedor" id="vendedor" />
          </span></div></td>
        </tr>
        <tr>
          <td> </td>
          <td> </td>
        </tr>
      </table>
      <table width="332" border="0">
        <tr>
          <td width="178" class="style7 style13 style13">MES:</td>
          <td width="144"><div align="right"> <span class="style7 style13 style13">
            <input type="text" name="mes" id="mes" />
          </span></div></td>
        </tr>
        <tr>
          <td> </td>
          <td> </td>
        </tr>
      </table>
      <table width="332" border="0">
        <tr>
          <td width="178" class="style7 style13 style13">ANO:</td>
            <td width="144"><div align="right">
              <span class="style7 style13 style13">
                <input type="text" name="ano" id="ano" />
            </span></div></td>
          </tr>
        <tr>
          <td> </td>
            <td><div align="right">
              <span class="style7 style13 style13">
                <input type="submit" name="button" id="button" value="Buscar" />
              </span></div></td>
          </tr>
        </table>
    </form></td>
  </tr>
</table>
</body>
</html>

resultado.php:

<?php
include "config.php"; //conexão mysql

$vendedor = $_POST["vendedor"];
$mes = $_POST["mes"];  
$ano = $_POST["ano"];  

$exec = mysql_query("SELECT * FROM os WHERE (vendedor LIKE '%".$vendedor."%' AND mes LIKE '%".$mes."%' AND ano LIKE '%".$ano."%')") or die("<script>alert('ERRO! Não foi possível conectar ao banco de dados.');location.href='javascript:history.go(-1)';</script>");
$total = mysql_num_rows($exec);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Relatório de OS</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<img src="Imagens/FreeTravelBrazilLogo.png" width="200" height="69" />
<table width="100%" border="0" cellpadding="0" cellspacing=" 0">
  <tr>
    <td width="15"><div align="center"><img src="Imagens/7513_32x32.png" width="32" height="32" /></div></td>
    <td><strong>Free Travel Turismo: Relatório de OS : <?php echo $row_Recordset1['vendedor']; ?>, <?php echo $row_Recordset1['mes']; ?>, <?php echo $row_Recordset1['ano']; ?></strong></td>
  </tr>
  <tr>
    <td> </td>
    <td><table width="100%" border="0" align="center">
      <tr bgcolor="#0099FF">
        <td bgcolor="#99FF00">OS N°</td>
        <td bgcolor="#99FF00">Reserva N°</td>
        <td bgcolor="#99FF00">Funcionario</td>
        <td bgcolor="#99FF00">Mes Lançado</td>
        <td bgcolor="#99FF00">Ano Lançado</td>
        <td bgcolor="#99FF00">Pax</td>
        <td bgcolor="#99FF00">Serviço</td>
        <td bgcolor="#99FF00">Motorista</td>
        <td bgcolor="#99FF00">Guia</td>
        <td bgcolor="#99FF00">Vendedor</td>
        <td bgcolor="#99FF00">Valor</td>
      </tr>
      <?php while ($row_Recordset1 = mysql_fetch_array($exec)) { ?>
      <tr>
        <td><?php echo $row_Recordset1['codigo']; ?></td>
        <td><?php echo $row_Recordset1['codigo2']; ?></td>
        <td><?php echo $row_Recordset1['funcionario']; ?>  </td>
        <td><?php echo $row_Recordset1['mes']; ?>  </td>
        <td><?php echo $row_Recordset1['ano']; ?></td>
        <td><?php echo $row_Recordset1['pax']; ?>  </td>
        <td><?php echo $row_Recordset1['servico']; ?>  </td>
        <td><?php echo $row_Recordset1['motorista']; ?>  </td>
        <td><?php echo $row_Recordset1['guia']; ?>  </td>
        <td><?php echo $row_Recordset1['vendedor']; ?>  </td>
        <td><?php echo $row_Recordset1['valor_total']; ?>  </td>
      </tr>
      <?php }  ?>
    </table></td>
  </tr>
</table>
<table width="54" border="0" align="right">
  <tr>
    <td><a href="#" onclick="window.print();"><img src="Imagens/Print_48.png" alt="ASD" width="48" height="48" border="0" /></a></td>
  </tr>
</table>
</p>
<a href="busca_os8.php" class="style19">Fazer nova busca</a>
</body>
</html>

 

 

[RESOLVIDO]

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.