Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Meu carrinho de compras está com problema sério, ele não está fazendo um carrinho de comprars pra cada cliente ele simplesmente vai juntando os produtos de todos os clientes no site.
por exemplo abri duas abas no browser loguei cum um user em cada aba, fiz add produtos nos carrinhos dos dois sé os dois carrinho se juntaram formando um carrinho so com os produtos dos dois usuários,
Como resolver?
Processa.php
<?php
session_start();
if(IsSet($_SESSION["nome_usuario"]))
$nome_usuario = $_SESSION["nome_usuario"];
if(IsSet($_SESSION["senha_usuario"]))
$senha_usuario = $_SESSION["senha_usuario"];
header("Content-Type: text/html; charset=ISO-8859-1",true) ;
//Instaciar a página do carrinho
$pagina='compra.php';
//Iniciar a class
class shopping{
private $banco='bd ronmusic';
private $senha='';
private $login='root';
private $hostname='localhost';
//Conexão com o banco de dados
function conexao(){
Mysql_connect($this->hostname,$this->login,$this->senha) or die ("não foi estabelecida uma conexão");
mysql_select_db($this->banco) or die("Não foi possível selecionar o banco".mysql_error());
mysql_query("SET NAME 'utf8'");
mysql_query("SET caracter_set_conneticon=utf8");
mysql_query("SET caracter_set_results=utf8");
}if($_SESSION){
//Separar nome de quantidade ou valores
foreach($_SESSION as $nome=> $quantidade){
//verificar se a quantidade não está zerada
if($quantidade>0){
if(substr($nome,0,9)=='produtos_'){
//Pegar ID da Session
$id=substr($nome,9,(strlen($nome)-9));
//Monta o carrinho
$PD=mysql_query("select cod_instrumento,nome,valor from instrumento where cod_instrumento=".mysql_real_escape_string((int)$id)) or die(mysql_error());
while($list=mysql_fetch_assoc($PD)){
$subtotal=$quantidade * $list['valor'];
echo'
<tr>
<td width="120" class="style4"><div align="center"><input type="text" size="25" value="'.$list['nome'].'" disabled="disabled" /><input type="hidden" size="25" value="'.$list['nome'].'" name="txt_produtonome[]" visible="false"/></div></td>
<td width="60"><div align="center"><span class="style4"><input type="text" size="3" value="'.$quantidade.'" disabled="disabled"/><input type="hidden" size="3" value="'.$quantidade.'" name="txt_quantidade[]"/></span></div></td>
<td width="76"><div align="center"><a href="processa.php?add='.(int)$id.'"><img src="mais.png" width="30" height="30"></a></div></td>
<td width="76"><div align="center"> </a></div></td>
<td width="76"><div align="center"><a href="processa.php?menos='.(int)$id.'"><img src="menos.jpg" width="30" height="10"></a></div></td>
<td width="76"><div align="center"><a href="processa.php?delete='.(int)$id.'"><img src="delete.png" width="30" height="30"></a></div></td>
<td width="72"><div align="center"><span class="style4"><input type="text" size="8" value="'.number_format($list['valor'],2).'" disabled="disabled"/><input type="hidden" size="8" value="'.$list['valor'].'" name="txt_valor[]"/></span></div></td>
<td width="77" class="style4"><div align="center"><input type="text" size="9" value="'.number_format($subtotal,2).'" disabled="disabled"/><input type="hidden" size="9" value="'.$subtotal.'" name="txt_subtotal[]" /></div></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>';
}
}
$total+=$subtotal;
}
}
}
if($total==0){
echo'<tr>
<td><a href="principal.php"><img src="cont_comprar.gif" width="200" height="30"></a><span class="style4">Carrinho vazio!</span></td>
</tr>'; echo' </tr>
<tr>
<td><a href="principal.php"><img src="cont_comprar.gif" width="200" height="30"></a></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><span class="style4">Total: '.number_format($total,2).'</span></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><input type="submit" name="submit" value="encomenda"><span class="style4">Finalizar Encomenda</span></td>
</tr>';
}
}
//fim class
}
//verifição de adição
if(isset($_GET['add'])){
$conn=new shopping();
$conn-> conexao();
$qt=mysql_query("select cod_instrumento,quant_estoque from instrumento where cod_instrumento=".mysql_real_escape_string((int)$_GET['add']));
$list=mysql_fetch_assoc($qt);
if($_SESSION['produtos_'.$_GET['add']] != $list['quant_estoque']){
$_SESSION['produtos_'.$_GET['add']] +='1';
}
header("location: ".$pagina);
}if(isset($_GET['menos'])){
$_SESSION['produtos_'.$_GET['menos']]--;
header("location: ".$pagina);
}if(isset($_GET['delete'])){
$_SESSION['produtos_'.$_GET['delete']]='0';
header("location: ".$pagina);
}
?>
compra.php
<?
header("Content-Type: text/html; charset=ISO-8859-1",true) ;
?><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
include "valida_cookies.php";
require 'processa.php';
$conecta= new shopping();
$conecta->conexao();
?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">font: 100% Verdana, Arial, Helvetica, sans-serif;
background:url(fundo3.jpg) repeat top center #FFF;;
margin: 8; / it's good practice to zero the margin and padding of the body element to account for differing browser defaults /
padding: 1000;
text-align: center; / this centers the container in IE 5 browsers. The text is then set to the left aligned default in the #container selector */
color: #000000;
}
.thrColAbs #container {
border-radius: 100px;
position: relative; / adding position: relative allows you to position the two sidebars relative to this container /
width: 1000px; / using 20px less than a full 800px width allows for browser chrome and avoids a horizontal scroll bar /
background: #FFFFFF;
margin: 0 auto; / the auto margins (in conjunction with a width) center the page /
border: 0px solid #000000;
text-align: left; / this overrides the text-align: center on the body element. /
}
/*
*/
.thrColAbs #sidebar1 {
border-radius: 40px;
position: absolute;
top: 192px;
left: 0px;height: 590px;
background-color: #EFEFEF;
}
.thrColAbs #sidebar3 {
border-radius: 40px;
position: absolute;
top: 828px;
left: 0px;height: 305px;
background-color: red;
}border-radius: 40px;
position: absolute;
top: 188px;
right: -1px;height: 597px;
background-color: #EFEFEF;
}
.thrColAbs #sidebar4 {
border-radius: 40px;
position: absolute;
top: 833px;
right: 0px;height: 304px;
background-color: #EFEFEF;
}float: right;
border-radius: 40px;
margin-left: 8px;
}float: left;
border-radius: 40px;
margin-right: 8px;
}</style><!--[if IE 5]>
<style type="text/css"><script src="Website ron music/SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="Website ron music/SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<style type="text/css">.style1 {
font-family: "Courier New", Courier, monospace;
color: #FFF;
}</style>
</head>
<body class="thrColAbs">
<div id="container">
<center>
<img src="s.png" width="200" height="168" /><img src="topo1.png" width="799" height="108" />
</center>
<div id="mainContent">
<p> </p>
<p> </p>
<h1><center>
<form name="encomenda" method="post" action="encomenda.php">
<table width="486" border="0">
<tr></tr>
<tr>
<td width="120" class="style4"><div align="center"><a href="comocomprar.php"><font size="+1"color="red">Como comprar?</font></a></div></td>
</tr><tr>
<tr>
<td width="120" class="style4"><div align="center"><font color="red"> </font></div></td>
</tr><tr>
<td width="120" class="style4"><div align="center">Produto</div></td>
<td width="60"><div align="center"><span class="style4">Quant</span></div></td>
<td width="76"><div align="center"><span class="style4"></span></div></td>
<td width="76"><div align="center"><span class="style4"></span></div></td> <td width="76"><div align="center"><span class="style4"></span></div></td>
<td width="76"><div align="center"><span class="style4">Excluir</span></div></td>
<td width="72"><div align="center"><span class="style4">Valor Unitário</span></div></td>
<td width="77" class="style4"><div align="center">Subtotal</div></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<?php
$conecta->carrinho();
?>
</table>
</form>
<h6> </h6>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</center>
</h1>
<h4><center>Todos os direitos reservados © 2009 - 2011</h4>
<center> <h5> </h5>
<h5><font color="white"></h5>
<!-- end #mainContent -->
</div>
<div id="sidebar1">
<p> </p>
<ul id="MenuBar2" class="MenuBarHorizontal">
<a href="mapa.php">Mapa do Site</a> <br />
<a href="Principal.php">Principal</a> <a href="#"></a> <a href="Lancamentos.php">Lançamentos</a> <a href="#"></a> <a href="Ofertas.php">Ofertas</a> <a href="#"></a>
<li class="MenuBarItemHover"><a href= "#" target="_parent" class="MenuBarItemSubmenu">Acessórios</a>
<ul>
<li><a href="Acessorios cordas.php">Cordas</a></li>
<li><a href="acessorios teclas.php">Teclas</a></li>
<li><a href="acessorios sopro.php">Sopro</a></li>
<li><a href="acessorios percussao.php">Percussão</a></li>
</ul>
</li>
<li class="MenuBarItemHover"><a href= "#" target="_parent" class="MenuBarItemSubmenu">Cordas</a>
<ul>
<li><a href="guitarra.php">Guitarra</a></li>
<li><a href="Baixo.php">Baixo</a></li>
<li><a class="MenuBarItemSubmenu" href="#">Violão</a>
<ul>
<li><a href="Violao Aco.php">Aço</a></li>
<li><a href="Violao nylon.php">Nylon</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="MenuBarItemSubmenu" href="#">Teclas</a>
<ul>
<li><a href="Teclado.php">Teclado</a></li>
<li><a href="Orgao.php">Orgão</a></li>
<li><a class="MenuBarItemSubmenu" href="#">Piano</a>
<ul>
<li><a href="Piano acustico.php">Acústico</a></li>
<li><a href="piano eletrico.php">Elétrico</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="MenuBarItemSubmenu" href="#">Sopro</a>
<ul>
<li><a href="Saxofone.php">Saxofone</a></li>
<li><a href="Trombone.php">Trombone</a></li>
<li><a href="Trompete.php">Trompete</a></li>
<li><a class="MenuBarItemSubmenu" href="#">Flauta</a>
<ul>
<li><a href="Flauta Transversal.php">Tranversal</a></li>
<li><a href="Flauta doce.php">Doce</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="MenuBarItemSubmenu" href="#">Percussão</a>
<ul>
<li><a class="MenuBarItemSubmenu" href="#">Bateria</a>
<ul>
<li><a href="Bateria Acustico.php">Acústico</a></li>
<li><a href="bateria eletrica.php">Elétrico</a></li>
</ul>
</li>
<li><a href="Cajon.php">Cajon</a></li>
<li><a href="Pandeiro.php">Pandeiro</a></li>
</ul>
</li>
<li><a class="MenuBarItemSubmenu" href="#">Amplificadores</a>
<ul>
<li><a href="ampguitarra.php">Guitarra</a></li>
<li><a href="ampteclado.php">Teclado</a></li>
<li><a href="ampviolao.php">Violão</a></li>
<li><a href="ampbaixo.php">Baixo</a></li>
</ul>
</li>
<li><a class="MenuBarItemSubmenu" href="#">Cases e bags</a>
<ul>
<li><a href="Cb cordas.php">Cordas</a></li>
<li><a href="CB teclas.php">Teclas</a></li>
<li><a href="CB sopro.php">Sopro</a></li>
<li><a href="CB percussao.php">Percussão</a></li>
</ul>
</li>
</ul>
<p> </p>
<p><img src="musica03.gif" alt="a" />
<!-- end #sidebar1 -->
</p>
</div>
<div id="sidebar3">
<h4><font color="#000000"> <span class="style1"> Destaque da semana</span></h4>
<?php
include "conexao.php";
?>
<?php
$cod= file_get_contents("destaque.txt");
$res= mysql_query("select * from instrumento where cod_instrumento=$cod");
$registro=mysql_num_rows($res);
$i=1;$quant=$list['quant_estoque'];
if($quant>=1){
if($i>$looph){
echo'<br>
<td align="center" valign="top" bgcolor="white"><a href="desc_instrumento.php?instru='.$list['cod_instrumento'].'">
<img src="'.$list['caminho_foto'].'" width="205" height="180" "/></a><br><br><font size="2"> <font color="gray"</font> </font>
</td> ?>
<p> </p>
</div>
<div id="sidebar2">
<form method="post" action="login.php">
<p>Username:</p>
<p>
<input name="username" type="text" />
</p>
<p>Senha:</p>
<p>
<input name="senha" type="password" />
</p>
<p>
<input name="submit" type="submit" value="Enviar"/>
<input name="button" type="button" value="Limpar"/>
</p>
<p><a href="logout.php">logout</a></p>
<ul id="MenuBar" class="MenuBarHorizontal">
<a href="Servico.php">Serviços</a>
</ul>
<ul id="MenuBar3" class="MenuBarHorizontal">
<a href="faleconosco.php">Fale conosco</a>
</ul>
<ul id="MenuBar4" class="MenuBarHorizontal">
<a href="Unidades.php">Unidades</a>
</ul>
<ul id="MenuBar4" class="MenuBarHorizontal">
<a href="cadastro.php"><b>Cadastre-se</b></a>
</ul>
<p> <a href="portal.php"><img src="ss.png" width="118" height="122" /></a>Procurar no site: </p>
<p><form name="frmBusca" method="post" action="pesquisa.php" >
<p>
<input type="text" name="palavra" />
</p>
<p>
<input type="submit" value="Procurar" />
</p>
</form>
</div>
<div id="sidebar4">
<form action="enquete/grava.php" method="post" name="form1" id="form1">
<table height="250" border="0" cellpadding="0" cellspacing="1">
<tr>
<td colspan="2" class="style1"><center>
<font color="#000000">Enquete:</td>
</tr>
<tr>
<td colspan="2" class="style1"><center>
<font color="#000000"> <br />
<?php include ("enquete/pergunta.txt"); ?>
<br /> </td>
</tr>
<tr class="style1">
<td width="84"> </td>
</tr>
<tr class="style1">
<td height="23"><div align="right">
<input name="voto" type="radio" value="R" />
</div></td>
<td width="324"><font color="#000000">
<?php include ("enquete/op1.txt"); ?></td>
</tr>
<tr class="style1">
<td height="23"><div align="right">
<input name="voto" type="radio" value="B" />
</div></td>
<td width="324"><font color="#000000">
<?php include("enquete/op2.txt"); ?></td>
</tr>
<tr class="style1">
<td height="23"><div align="right">
<input name="voto" type="radio" value="O" />
</div></td>
<td><font color="#000000">
<?php include("enquete/op3.txt"); ?></td>
</tr>
<tr> </tr>
<tr class="style1">
<td height="23"><div align="right">
<input name="voto" type="radio" value="A" />
</div></td>
<td><font color="#000000">
<?php include("enquete/op4.txt"); ?></td>
</tr>
<tr class="style1">
<td width="40" height="5"> </td>
</tr>
<tr>
<td height="27" colspan="2"><div align="center">
<input type="submit" name="Submit2" value="Votar" />
</div></td>
</tr>
<tr class="style1">
<td width="40" height="5"> </td>
</tr>
<tr>
<td colspan="2" align="center" class="style1"><a href="enquete/resultado.php">Resultado</a></td>
</tr>
<tr>
<td colspan="2" align="center" class="style1"> </td>
</tr>
</table>
</form>
<p> </p>
</div>
<!-- end #container -->
</div>
<script type="text/javascript">var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
var MenuBar2 = new Spry.Widget.MenuBar("MenuBar2", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});</script>
</body>
</html>Carregando comentários...