
Raio da Noite
Membros-
Total de itens
4 -
Registro em
-
Última visita
Tudo que Raio da Noite postou
-
Problema com resultado de pesquisa interna!
pergunta respondeu ao Raio da Noite de Raio da Noite em PHP
Não mudou nada continuo o mesmo resultado sem os produtos. -
Estou com dois problemas para pesquisa interna em meu site, a pesquisa é feita por meio de um textfield e um combobox, escolhendo assim a categoria especifica que quer buscar, categorias estas que a combobox traz do banco de dados bom o problema: Primeiro um campo especifico no select que vem da tabela do banco não deveria aparecer o restante sim, ou seja todas as categorias menos a categoria que tem o nome geral, e ele está me trazendo todas as categorias pra buscar! Segundo aparentemente ele está buscando corretamente informando os valores de quantos produtos achou conforme os existentes nas categorias respectivas, porém ele não exibe estes produtos, fica em branco depois das mensagens pré definidas por mim alguém pode dar uma ajuda? Obrigado desde já! Segue os codigos: MENU.PHP: <?php $id_cat = $_GET["id_cat"]; $id_subcat = $_GET["id_subcat"]; ?> <!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=iso-8859-1" /> <title>Festas e Alegorias tudo para Festas de Época - Menu</title> <style type="text/css"> <!-- body { margin-top: 0px; } .style1 { font-family: Arial, Helvetica, sans-serif; font-size: 9px; } --> </style></head> <body> <table width="188" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="3"> </td> </tr> <tr> <td colspan="3"><div align="center"><img src="img/bot_produtos.png" width="187" height="39" /></div></td> </tr> <tr> <td colspan="3"> </td> </tr> <tr> <td width="7"> <div align="left"></div></td> <td width="171"><?php $sql_cat = mysql_query("SELECT * FROM categorias"); while($coluna_cat = mysql_fetch_array($sql_cat)) { if ($coluna_cat[id_categoria] !=1) echo "<a href = \"index.php?link=2&id_cat=$coluna_cat[id_categoria]\"> $coluna_cat[categoria] </a> <br>"; if ($id_cat ==$coluna_cat[id_categoria]) { $sql_subcat = mysql_query("SELECT * FROM subcategorias WHERE id_categoria='$id_cat'"); while($coluna_subcat = mysql_fetch_array($sql_subcat)) { echo "- <a href = \"index.php?link=2&id_cat=$coluna_subcat[id_categoria]&id_subcat=$coluna_subcat[id_subcategoria]\">$coluna_subcat[subcategoria] </a> <br>"; } } } ?></td> <td width="10"> </td> </tr> <tr> <td colspan="3"> </td> </tr> <tr> <td colspan="3"><div align="center"><img src="img/linha.png" width="187" height="4" /></div></td> </tr> <tr> <td colspan="3"> </td> </tr> <tr> <td colspan="3"><form id="form1" name="form1" method="POST" action="index.php?link=3"> <div align="center" class="style1">Digite um produto para buscar:</br> <label> <input name="txt_valor" type="text" id="txt_valor" size="25" /> </label></br> <label> <br /> <select name="txt_cat" id="txt_cat"> <option value ="">Todas as Categorias</option> <?php $sql = mysql_query("SELECT * FROM categorias ORDER BY categoria"); while ($coluna = mysql_fetch_array($sql)) { ?> <option value="<?php echo $coluna[id_categoria] ?>"<?php if ($coluna[id_categoria]==$txt_cat) echo "selected"; ?>> <?php echo $coluna[categoria]; ?></option> <?php } ?> </select> <input type="image" name="imageField" src="img/pesquisar.png" /> </label> </div> </form> </td> </tr> </table> </body> </html> BUSCA.PHP <?php $txt_valor = $_POST["txt_valor"]; $i = $_GET['i']; $txt_cat = $_POST["txt_cat"]; ?> <!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=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>Resultado da Pesquisa:</td> </tr> <tr> <td><img src="img/linha2.png" width="660" height="4" /></td> </tr> <?php if ($txt_cat!="") $tem_categoria = "AND id_categoria='$txt_cat'"; $sql_geral = mysql_query("SELECT * FROM produtos WHERE produto LIKE '%".$txt_valor."%' order by id_produto Desc"); $qtde_produtos = mysql_num_rows($sql_geral); $i = 0; ?> <tr> <td>Foram encontrados <i><?php echo $qtde_produtos ?></i> resultados para sua pequisa de Produto(s) com a palavra <i><?php echo $txt_valor ?></i>:</td> </tr> <tr> <td><img src="img/linha2.png" width="660" height="4" /></td> </tr> <tr> <?php if ($qtde_produtos == 0) { ?> <td>Nenhum Produto encontrado com <i><?php echo $txt_valor ?></i></td> <? } else { ?> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="4"> <tr> <?php while ($i < $qtde_produtos) { ?> <td width="50%" align="center"><table width="100%" border="1" cellspacing="0" cellpadding="0"> <tr> <td><?php echo "<img src = admin/img/produto/".@mysql_result($sql_geral,$i,foto)." border =2 width=75 align= left>"; ?> <b> <p align="center"> <?php echo @mysql_result($sql_geral,$i,produto); ?> <b> </p> </p></td> </tr> <tr> <td align="center"><form action="" method="post"> <label> <input type="image" name="imageField" src="img/comprar.png" /> </label> <label> <input type="image" name="imageField2" src="img/detalhes.png" /> </label> </form></td> </tr> </table></td> <?php $i++; if ($i%2==0) echo "</tr>"; } ?> </table> <?php } ?> </td> </tr> </table></td> </tr> </table> </body> </html>
-
Problema para inserir dados web no banco
pergunta respondeu ao Raio da Noite de Raio da Noite em PHP
problema resolvido com a sua dica muito obrigado, segue código correto para que o tópico fique completo: <?php include "conexao.php"; extract($_REQUEST); $id = $_POST["id"]; $txt_id_categoria = $_POST["txt_id_categoria"]; $txt_id_subcategoria = $_POST["txt_id_subcategoria"]; $txt_categoria = $_POST["txt_categoria"]; $txt_subcategoria = $_POST["txt_subcategoria"]; $txt_produto = $_POST['txt_produto']; $txt_foto = $_POST["txt_foto"]; $txt_descricao = $_POST["txt_descricao"]; $Inserir = $_POST['Inserir']; if($Inserir =="ok"){ $sql = "INSERT INTO produtos (id_categoria, id_subcategoria, produto, foto, descricao) VALUES ('$txt_id_categoria', '$txt_id_subcategoria', '$txt_produto', '$txt_foto', '$txt_descricao')"; mysql_query($sql) or die ("Não foi possível Inserir dados"); } $Alterar= $_POST['Alterar']; if ($Alterar == "ok"){ $sql = "UPDATE produtos SET id_categoria = '$txt_id_categoria', id_subcategoria = '$txt_id_subcategoria', produto = '$txt_produto', foto = '$txt_foto', descricao = '$txt_descricao' WHERE id_produto = '$id'"; mysql_query($sql) or die ("Não foi possível Inserir dados"); } if($_GET['Excluir'] == "ok"){ $id = $_GET['id']; mysql_query ("DELETE FROM produtos WHERE id_produto ='$id'")or die (mysql_error()); }else{ } ?> <!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=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <table width="900" border="0" align="center"> <tr> <td colspan="2"><?php include "cabecalho.php"; ?></td> </tr> <tr> <td width="197"><?php include "menu.php"; ?></td> <td width="693"><table width="100%" border="0"> <tr> <td><div align="center"> <p>Produtos</p> <?php $acao = $_GET["acao"]; $id = $_GET["id"]; if ($acao != "") { $sql = "select p.*, c.*, s.* from produtos p, categorias c, subcategorias s where p.id_categoria = c.id_categoria and p.id_subcategoria = s.id_subcategoria and p.id_produto = '$id'"; $resultado = mysql_query ($sql); $linha = mysql_fetch_array($resultado); $produto = $linha["produto"]; $foto = $linha["foto"]; $descricao = $linha["descricao"]; $subcategoria = $linha["subcategoria"]; $categoria = $linha["categoria"]; $id_subcategoria = $linha["id_subcategoria"]; $id_categoria = $linha["id_categoria"]; ?> <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table width="475" border="1" align="center" cellpadding="2"> <tr> <td width="93">Categoria:</td> <td width="310"> <select name = "txt_id_categoria" id="txt_id_categoria"> <?php $sql_cat = "select * from categorias order by categoria"; $result = mysql_query($sql_cat); while ($registro = mysql_fetch_array($result)) { $valor = $registro["id_categoria"]; if ($id_categoria == $valor) $selecionado = "selected"; else $selecionado = ""; print "<option value = \"$valor\"$selecionado> $registro[categoria] </option>"; } ?> </select> </td> </tr> <tr> <td width="93">SubCategoria:</td> <td width="310"> <select name = "txt_id_subcategoria" id="txt_id_subcategoria"> <?php $sql_subcat = "select * from subcategorias order by subcategoria"; $result = mysql_query($sql_subcat); while ($registro = mysql_fetch_array($result)) { $valor = $registro["id_subcategoria"]; if ($id_categoria == $valor) $selecionado = "selected"; else $selecionado = ""; print "<option value = \"$valor\"$selecionado> $registro[subcategoria] </option>"; } ?> </select> </td> </tr> <tr> <td width="93">Produto:</td> <td> <input name="txt_produto" type="text" id="txt_produto" value= "<?php echo $produto; ?>" size="35" maxlength="100" /></td> </tr> <tr> <td width="93">Foto:</td> <td><input name="txt_foto" type="text" id="txt_foto" value= "<?php echo $foto; ?>"/></td> </tr> <tr> <td width="93">Descrição:</td> <td><textarea name="txt_descricao" cols="35" rows="5" id="txt_descricao"><?php echo $descricao; ?></textarea></td> </tr> <tr> <td colspan="2"><label> <div align="right"> <input type="hidden" name="id" value= "<?php echo $id ?>" /> <input type="hidden" name=" <?php echo $acao ?>" value ="ok" /> <input type="submit" name="Submit" value="OK" /> </div> </label></td> </tr> </table> </form> <?php } else { ?> <table width="99%" border="1"> <tr> <td width="26%"><div align="center">Categorias:</div></td> <td width="26%"><div align="center">SubCategorias:</div></td> <td width="36%"><div align="center">Produtos:</div></td> <td colspan="2"><div align="center">Ação:</div></td> </tr> <?php $sql = "select p.*, c.*, s.* from produtos p, categorias c, subcategorias s where p.id_categoria = c.id_categoria and p.id_subcategoria = s.id_subcategoria order by p.produto"; $resultado = mysql_query($sql); while ($coluna = mysql_fetch_array($resultado)) { ?> <tr> <td><?php echo $coluna["categoria"] ?></td> <td><?php echo $coluna["subcategoria"] ?></td> <td><?php echo $coluna["produto"] ?></td> <td width="6%"><div align="center"><a href="?acao=Alterar&id=<?php echo $coluna["id_produto"];?>" > <img src="img/editar.png" alt="Editar" width="30" height="30" border = "0" /></a></div></td> <td width="6%"><div align="center"><a href="?Excluir=ok&id=<?php echo $coluna["id_produto"];?>" > <img src="img/excluir.png" alt="Excluir" width="30" height="30" border = "0" /></a></div></td> </tr> <?php } ?> <tr> <td colspan="5"><div align="right"><a href="?acao=Inserir"> <img src="img/inserir.png" alt="Inserir" width="80" height="25" border = "0" /></a></div></td> </tr> </table> <?php } ?> <p> </p> </div></td> </tr> </table></td> </tr> <tr> <td colspan="2"><div align="center"> <?php include "rodape.php"; ?> </div></td> </tr> </table> </body> </html> -
Bom dia a todos, venho pedir encarecidamente ajuda com erro na seguinte pagina: <?php include "conexao.php"; extract($_REQUEST); $acao = $_POST["acao"]; $id = $_POST["id"]; $txt_id_categoria = $_POST["txt_id_categoria"]; $txt_id_subcategoria = $_POST["txt_id_subcategoria"]; $txt_categoria = $_POST["txt_categoria"]; $txt_subcategoria = $_POST["txt_subcategoria"]; $txt_produto = $_POST['txt_produto']; $txt_foto = $_POST["txt_foto"]; $txt_descricao = $_POST["txt_descricao"]; if ( $acao =="Inserir" ){ $sql = "INSERT INTO produtos (id_categoria, id_subcategoria, produto, foto, descricao) VALUES ('$txt_id_categoria', '$txt_id_subcategoria', '$txt_produto', '$txt_foto, '$txt_descricao')"; mysql_query($sql) or die ("Não foi possível Inserir dados"); } if($acao =="Alterar"){ $sql = "UPDATE produtos SET id_categoria = $'txt_id_categoria', id_subcategoria = $'txt_id_subcategoria', produto = $'txt_produto', foto = $'txt_foto', descricao = $'txt_descricao' WHERE id_produto = '$id'"; mysql_query($sql) or die ("Não foi possível Inserir dados"); } if($_GET['Excluir'] == "ok"){ $id = $_GET['id']; mysql_query ("DELETE FROM produtos WHERE id_produto ='$id'")or die (mysql_error()); }else{ } ?> <!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=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <table width="900" border="0" align="center"> <tr> <td colspan="2"><?php include "cabecalho.php"; ?></td> </tr> <tr> <td width="197"><?php include "menu.php"; ?></td> <td width="693"><table width="100%" border="0"> <tr> <td><div align="center"> <p>Produtos</p> <?php $acao = $_GET["acao"]; $id = $_GET["id"]; if ($acao != "") { $sql = "select p.*, c.*, s.* from produtos p, categorias c, subcategorias s where p.id_categoria = c.id_categoria and p.id_subcategoria = s.id_subcategoria and p.id_produto = '$id'"; $resultado = mysql_query ($sql); $linha = mysql_fetch_array($resultado); $produto = $linha["produto"]; $foto = $linha["foto"]; $descricao = $linha["descricao"]; $subcategoria = $linha["subcategoria"]; $categoria = $linha["categoria"]; $id_subcategoria = $linha["id_subcategoria"]; $id_categoria = $linha["id_categoria"]; ?> <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table width="475" border="1" align="center" cellpadding="2"> <tr> <td width="93">Categoria:</td> <td width="310"> <select name = "txt_id_categoria" id="txt_id_categoria"> <?php $sql_cat = "select * from categorias order by categoria"; $result = mysql_query($sql_cat); while ($registro = mysql_fetch_array($result)) { $valor = $registro["id_categoria"]; if ($id_categoria == $valor) $selecionado = "selected"; else $selecionado = ""; print "<option value = \"$valor\"$selecionado> $registro[categoria] </option>"; } ?> </select> </td> </tr> <tr> <td width="93">SubCategoria:</td> <td width="310"> <select name = "txt_id_subcategoria" id="txt_id_subcategoria"> <?php $sql_subcat = "select * from subcategorias order by subcategoria"; $result = mysql_query($sql_subcat); while ($registro = mysql_fetch_array($result)) { $valor = $registro["id_subcategoria"]; if ($id_categoria == $valor) $selecionado = "selected"; else $selecionado = ""; print "<option value = \"$valor\"$selecionado> $registro[subcategoria] </option>"; } ?> </select> </td> </tr> <tr> <td width="93">Produto:</td> <td> <input name="txt_produto" type="text" id="txt_produto" value= "<?php echo $produto; ?>" size="35" maxlength="100" /></td> </tr> <tr> <td width="93">Foto:</td> <td><input name="txt_foto" type="text" id="txt_foto" value= "<?php echo $foto; ?>"/></td> </tr> <tr> <td width="93">Descrição:</td> <td><textarea name="txt_descricao" cols="35" rows="5" id="txt_descricao"><?php echo $descricao; ?></textarea></td> </tr> <tr> <td colspan="2"><label> <div align="right"> <input type="hidden" name="id" value= "<?php echo $id ?>" /> <input type="hidden" name=" <?php echo $acao ?>" value ="ok" /> <input type="submit" name="Submit" value="OK" /> </div> </label></td> </tr> </table> </form> <?php } else { ?> <table width="99%" border="1"> <tr> <td width="26%"><div align="center">Categorias:</div></td> <td width="26%"><div align="center">SubCategorias:</div></td> <td width="36%"><div align="center">Produtos:</div></td> <td colspan="2"><div align="center">Ação:</div></td> </tr> <?php $sql = "select p.*, c.*, s.* from produtos p, categorias c, subcategorias s where p.id_categoria = c.id_categoria and p.id_subcategoria = s.id_subcategoria order by p.produto"; $resultado = mysql_query($sql); while ($coluna = mysql_fetch_array($resultado)) { ?> <tr> <td><?php echo $coluna["categoria"] ?></td> <td><?php echo $coluna["subcategoria"] ?></td> <td><?php echo $coluna["produto"] ?></td> <td width="6%"><div align="center"><a href="?acao=Alterar&id=<?php echo $coluna["id_produto"];?>" > <img src="img/editar.png" alt="Editar" width="30" height="30" border = "0" /></a></div></td> <td width="6%"><div align="center"><a href="?Excluir=ok&id=<?php echo $coluna["id_produto"];?>" > <img src="img/excluir.png" alt="Excluir" width="30" height="30" border = "0" /></a></div></td> </tr> <?php } ?> <tr> <td colspan="5"><div align="right"><a href="?acao=Inserir"> <img src="img/inserir.png" alt="Inserir" width="80" height="25" border = "0" /></a></div></td> </tr> </table> <?php } ?> <p> </p> </div></td> </tr> </table></td> </tr> <tr> <td colspan="2"><div align="center"> <?php include "rodape.php"; ?> </div></td> </tr> </table> </body> </html> É a pagina da loja virtual que estou montando, consigo ver os dados na tabela pelo navegador do produto que cadastrei no banco via php myadmin, mas ao inserir dados ou alterar ele volta pra tabela sem ter inserido ou alterado e sem apresentar mensagem de erro somente ignora o que fiz, alguém pode me ajudar? desde já muito obrigado!