Ir para conteúdo
Fórum Script Brasil

lbfrb

Membros
  • Total de itens

    2
  • Registro em

  • Última visita

Sobre lbfrb

lbfrb's Achievements

0

Reputação

  1. estamos tentando mostrar o carrinho, com o produto selecionado mas aparece o seguinte erro: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Barbie - Sereia Luzes Arco-Ãris, 1, 99.99, 99.99)' at line 1' in C:\wamp\www\fab-certo-30-11\carrinho.php on line 44 PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Barbie - Sereia Luzes Arco-Ãris, 1, 99.99, 99.99)' at line 1 in C:\wamp\www\fab-certo-30-11\carrinho.php on line 44 Call Stack # Time Memory Function Location 1 0.0000 265552 {main}( ) ..\carrinho.php:0 2 0.0156 281512 execute ( ) ..\carrinho.php:44 o código: <?php session_start(); if (isset($_SESSION["email"])) { $sessao = session_id(); } else { $msg = "Não há usuario logado"; //header("Location:carrinho_problemas.php"); } include ("conexao.php"); //se é é enviado um ID pela URL, o produto deverá ser incluido no carrinho if (isset($_GET["id"])) { $idprodutos = $_GET["id"]; $sql = "select * from produtos where idprodutos = $idprodutos"; $result= $conexao->prepare($sql); $result->execute(); if ( $linha = $result->fetch(PDO::FETCH_ASSOC) ) { $nome = $linha["nome"]; $preço = $linha["preço"]; $quant = 1; $total = $quant * $preço; $sql = "insert into itens values(null, $idprodutos, $sessao, $nome, $quant, $preço, $total)"; $result= $conexao->prepare($sql); /*$result->bindValue(":idprodutos", $idprodutos); $result->bindValue(":sessao", $sessao); //$result->bindValue(":idvendas", $idvendas); $result->bindValue(":nome", $nome); $result->bindValue(":quant", $quant); $result->bindValue(":preço", $preço); $result->bindValue(":total", $total) */ $result->execute(); } } if (isset($_POST["atualizar"])) { $quant = $_POST['quant']; // Se for diferente de vazio verificamos se é numérico if (is_array($quant)) { // Aqui percorremos o nosso array foreach($quant as $iditens => $quant) { // Verificamos se os valores são do tipo numeric if(is_numeric($iditens) && is_numeric($quant)) { $sql = "update itens set quant = $quant, total = $quant * preço where iditens = $iditens"; $result= $conexao->prepare($sql); $result->execute(); } } } } if (isset($_GET["excluir"])) { $excluir = $_GET['excluir']; $sql = "delete from itens where iditens = $excluir"; $result= $conexao->prepare($sql); $result->execute(); } $sql1 = "select * from itens where idsessao = '$sessao'"; $result1= $conexao->prepare($sql1); $result1->execute(); $sql2 = "select sum(total) as total from itens where idsessao = '$sessao'"; $result2= $conexao->prepare($sql2); $result2->execute(); $linha2 = mysql_fetch_array($result2); $total = number_format($linha2["total"],2,",","."); $_SESSION["total"] = $linha2["total"]; ?> <!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/links.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>Carrinho de Compras</h1> <form id="form1" name="form1" method="post" action="carrinho.php"> <table border="1" cellspacing="0" cellpadding="5"> <tr> <th scope="col">Produto</th> <th scope="col">Quantidade</th> <th align="right" scope="col">Preço</th> <th align="right" scope="col">Total</th> </tr> <?php while ($linha = mysql_fetch_array($result1)) {?> <tr> <td><?php echo $linha["Descricao"] ?> (<a href="carrinho.php?excluir=<?php echo $linha["CodCarrinho"] ?>">excluir</a>)</td> <td align="center"><input id="qtde" type="text" name="qtde[<?php echo $linha["CodCarrinho"] ?>]" value="<?php echo $linha["Quantidade"] ?>" size="10" /></td> <td align="right"><?php echo number_format($linha["preço"],2,",",".") ?></td> <td align="right"><?php echo number_format($linha["Total"],2,",",".") ?></td> </tr> <?php } ?> <tr> <td colspan="4" align="right" class="detaque_em_vermelho">Valor Total: R$ <?php echo $total ?></td> </tr> </table> <p> <input type="submit" name="atualizar" id="atualizar" value="Atualizar Valores" /> <a href="finalizar_compra1.php">Finalizar a Compra</a></p> </form> <?php if ($linha2["Total"] == 0) { echo"<script language=javascript> alert('O carrinho de compras está vazio, estamos redirecionando voce para escolher um produto !'); location.href = 'produtos_em_tabela.php'; //history.go(-1); </script>"; } ?> </body> </html> FIM o código: <?php session_start(); if (isset($_SESSION["email"])) { $sessao = session_id(); } else { $msg = "Não há usuario logado"; //header("Location:carrinho_problemas.php"); } include ("conexao.php"); //se é é enviado um ID pela URL, o produto deverá ser incluido no carrinho if (isset($_GET["id"])) { $idprodutos = $_GET["id"]; $sql = "select * from produtos where idprodutos = $idprodutos"; $result= $conexao->prepare($sql); $result->execute(); if ( $linha = $result->fetch(PDO::FETCH_ASSOC) ) { $nome = $linha["nome"]; $preço = $linha["preço"]; $quant = 1; $total = $quant * $preço; $sql = "insert into itens values(null, $idprodutos, $sessao, $nome, $quant, $preço, $total)"; $result= $conexao->prepare($sql); /*$result->bindValue(":idprodutos", $idprodutos); $result->bindValue(":sessao", $sessao); //$result->bindValue(":idvendas", $idvendas); $result->bindValue(":nome", $nome); $result->bindValue(":quant", $quant); $result->bindValue(":preço", $preço); $result->bindValue(":total", $total) */ $result->execute(); } } if (isset($_POST["atualizar"])) { $quant = $_POST['quant']; // Se for diferente de vazio verificamos se é numérico if (is_array($quant)) { // Aqui percorremos o nosso array foreach($quant as $iditens => $quant) { // Verificamos se os valores são do tipo numeric if(is_numeric($iditens) && is_numeric($quant)) { $sql = "update itens set quant = $quant, total = $quant * preço where iditens = $iditens"; $result= $conexao->prepare($sql); $result->execute(); } } } } if (isset($_GET["excluir"])) { $excluir = $_GET['excluir']; $sql = "delete from itens where iditens = $excluir"; $result= $conexao->prepare($sql); $result->execute(); } $sql1 = "select * from itens where idsessao = '$sessao'"; $result1= $conexao->prepare($sql1); $result1->execute(); $sql2 = "select sum(total) as total from itens where idsessao = '$sessao'"; $result2= $conexao->prepare($sql2); $result2->execute(); $linha2 = mysql_fetch_array($result2); $total = number_format($linha2["total"],2,",","."); $_SESSION["total"] = $linha2["total"]; ?> <!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/links.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>Carrinho de Compras</h1> <form id="form1" name="form1" method="post" action="carrinho.php"> <table border="1" cellspacing="0" cellpadding="5"> <tr> <th scope="col">Produto</th> <th scope="col">Quantidade</th> <th align="right" scope="col">Preço</th> <th align="right" scope="col">Total</th> </tr> <?php while ($linha = mysql_fetch_array($result1)) {?> <tr> <td><?php echo $linha["Descricao"] ?> (<a href="carrinho.php?excluir=<?php echo $linha["CodCarrinho"] ?>">excluir</a>)</td> <td align="center"><input id="qtde" type="text" name="qtde[<?php echo $linha["CodCarrinho"] ?>]" value="<?php echo $linha["Quantidade"] ?>" size="10" /></td> <td align="right"><?php echo number_format($linha["preço"],2,",",".") ?></td> <td align="right"><?php echo number_format($linha["Total"],2,",",".") ?></td> </tr> <?php } ?> <tr> <td colspan="4" align="right" class="detaque_em_vermelho">Valor Total: R$ <?php echo $total ?></td> </tr> </table> <p> <input type="submit" name="atualizar" id="atualizar" value="Atualizar Valores" /> <a href="finalizar_compra1.php">Finalizar a Compra</a></p> </form> <?php if ($linha2["Total"] == 0) { echo"<script language=javascript> alert('O carrinho de compras está vazio, estamos redirecionando voce para escolher um produto !'); location.href = 'produtos_em_tabela.php'; //history.go(-1); </script>"; } ?> </body> </html> FIM
  2. fiz uma enquete e está aparecendo dois erros: Warning: mysql_query() expects parameter 1 to be string, object given in C:\wamp\www\php\cadastrar2.php on line 74 Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in C:\wamp\www\php\cadastrar2.php on line 76 aqui está o meu programa (com a parte de banco de dados e tudo): <?php session_start(); include_once("conexao.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>Confirmação de Cadastro</title> </head> <body> <?php include "conexao.php"; $nomeequipe= $_REQUEST["nomeequipe"]; $jogador1= $_REQUEST["jogador1"]; $jogador2= $_REQUEST["jogador2"]; $jogador3= $_REQUEST["jogador3"]; $jogador4= $_REQUEST["jogador4"]; $jogador5= $_REQUEST["jogador5"]; $sala1= $_REQUEST["sala1"]; $sala2= $_REQUEST["sala2"]; $sala3= $_REQUEST["sala3"]; $sala4= $_REQUEST["sala4"]; $sala5= $_REQUEST["sala5"]; $turma1= $_REQUEST["turma1"]; $turma2= $_REQUEST["turma2"]; $turma3= $_REQUEST["turma3"]; $turma4= $_REQUEST["turma4"]; $turma5= $_REQUEST["turma5"]; try { $sql="insert into equipes values (null, :nomeequipe, :jogador1, :sala1, :turma1, :jogador2, :sala2, :turma2, :jogador3, :sala3, :turma3, :jogador4, :sala4, :turma4, :jogador5, :sala5, :turma5 )"; $result= $conexao->prepare($sql); $result->bindValue(":nomeequipe", $nomeequipe); $result->bindValue(":jogador1", $jogador1); $result->bindValue(":jogador2", $jogador2); $result->bindValue(":jogador3", $jogador3); $result->bindValue(":jogador4", $jogador4); $result->bindValue(":jogador5", $jogador5); $result->bindValue(":sala1", $sala1); $result->bindValue(":sala2", $sala2); $result->bindValue(":sala3", $sala3); $result->bindValue(":sala4", $sala4); $result->bindValue(":sala5", $sala5); $result->bindValue(":turma1", $turma1); $result->bindValue(":turma2", $turma2); $result->bindValue(":turma3", $turma3); $result->bindValue(":turma4", $turma4); $result->bindValue(":turma5", $turma5); $result->execute(); echo"Equipe cadastrada com sucesso!"; } catch (PDOException $erro) { header("location: erro.php?erro=Ocorreu o seguinte erro: ".$erro->getMessage()); } ?> <h1>Enquete</h1> <p>Parte do dinheiro arrecadado com o campeonato será doado para uma entidade. Para qual entidade você acredita que mais necessita da doação?</p> <?php if(isset($_SESSION['msg'])){ echo $_SESSION['msg']."<br><br>"; unset($_SESSION['msg']); } //pesquisar por produtos $result_opcao = "SELECT * FROM opcoes"; $resultado_opcao = mysql_query($conexao, $result_opcao); while($linha_opcao = mysql_fetch_assoc($resultado_opcao)){ echo $linha_opcao['id_opcao'] . "- " . $linha_opcao['nome'] . "<br>"; echo "Quantidade de votos: " . $linha_opcao['qntd_votos'] . "<br>"; echo "<a href='votar.php?id_opcao=".$linha_opcao['id_opcao']."'>votar</a><hr>"; } ?> <p>&nbsp;</p> <p><a href="index.php">Voltar para a página inicial</a></p> </body> </html> ================================================================================================= queria saber o que está acontecendo porque quando eu faço a enquete numa página sozinha, ela funciona, agora quando eu coloquei ela no cadastro, ela não funciona. Obrigada desde já e me desculpem pela ignorância
×
×
  • Criar Novo...