Jump to content


Photo

Problemas Em Código


  • Faça o login para participar
2 replies to this topic

#1 Gui 1

Gui 1

    Normal

  • Usuários
  • 88 posts
  • Sexo:Não informado
  • Localidade:Araras/SP
  • Interesses:Linguagens de programação,METEORUS(jogo online),Mu Online,Ultima Online,informática em geral.

Posted 05/06/2004, 19:22

Olhem pessoal, fiz uma loja virtual simples mais funcional aqui em casa,olhem:
Acalifa Flores
Tudo verde

Mas da um erro na página, ohem lá
Vou postar o script:
<?
/************************************************************************
ARQUIVO .........: Carrinho de compras simples: usado  no web site da Acalifa Flores
BY ..............: Guilherme Moreira Lizardo - guilhermeboby@ibest.com.br
************************************************************************/
//MONTA O ARRAY DE PRODUTOS
$produto[1][CODIGO]     =  "00001";
$produto[1][ARTISTA]     =   "Arranjo Amarelo de Flores";
$produto[1][ALBUM]       =   "Arranjos";
$produto[1][PRECO]       =   "15,25";
$produto[1][IMAGEM]      =   "../floriculturas/arranjoamarelo.jpg";

$produto[2][CODIGO]     =   "00002";
$produto[2][ARTISTA]     =   "Arranjo Bambus";
$produto[2][ALBUM]       =   "Arranjos";
$produto[2][PRECO]       =   "28,35";
$produto[2][IMAGEM]      =   "../floriculturas/arranjocombambus.jpg";

$produto[3][CODIGO]     =   "00003";
$produto[3][ARTISTA]     =   "Canteiro - Completo";
$produto[3][ALBUM]       =   "Canteiros";
$produto[3][PRECO]       =   "75,99";
$produto[3][IMAGEM]      =   "../floriculturas/canteiro.jpg";

$produto[4][CODIGO]     =   "00004";
$produto[4][ARTISTA]     =   "Coqueiros";
$produto[4][ALBUM]       =   "Árvores";
$produto[4][PRECO]       =   "30,00";
$produto[4][IMAGEM]      =   "../floriculturas/cantocoqueirinhos.jpg";


//TOTAL DE PRODUTOS POR LINHA
$total = 2;

?>

<html>
<head>
<title>Vendas</title>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
<STYLE type="text/css">
<!--
BODY {
scrollbar-face-color: #000000;
scrollbar-highlight-color: #FFFFFF;
scrollbar-3dlight-color: #C0C0C0;
scrollbar-darkshadow-color: #404040;
scrollbar-shadow-color: #808080;
scrollbar-arrow-color: #FFFFFF;
scrollbar-track-color: #FFFFFF;
}
-->
</STYLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>

<body bgcolor="#FFCC99">
<table width="773"  border="0" cellspacing="0" cellpadding="0">
   <tr>
    <td> <br>
    <table width="95%"  border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
          <td align='center'><div align="left"><font face='Arial' size='4'><b>Vendas</b></font></div></td>
      </tr>
    </table>
    <br>
    <br>
    <table width="95%"  border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
          <td><font face='Arial' size='2'>Confira abaixo, os &uacute;ltimos produtos 
            selecioandos no site:</font></td>
      </tr>
    </table>
    <br>  
    
	<form action="carrinho.php" method="post" name="frmcarrinho">
       <input type="hidden" name="opc_efetivar" value="1">
    <table width="90%"  border="0" align="center" cellpadding="0" cellspacing="0"> 
       <tr>
    <?
    //PEGA A CHAVE DO ARRAY
    $chave = array_keys($produto);
    
    //EXIBE OS PRODUTOS
  for($i=0; $i<sizeof($chave); $i++) {
     $indice    =   $chave[$i];
     $codigo    =   $produto[$indice][CODIGO];
     $artista   =   $produto[$indice][ARTISTA];
     $album     =   $produto[$indice][ALBUM];
     $preco     =   $produto[$indice][PRECO];
     $imagem    =   $produto[$indice][IMAGEM]; 
     
           //VERIFICA
        if($total == $atual) {
        echo "</tr><tr>";
     $atual = 0;
     } ?> 
     
          <td width="14%" height="100"><img src="<? echo $imagem; ?>" width="80" height="80" border="1"></td>
          <td width="36%">
    
    <table width="95%"  border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
             <td><font face='Arial' size='2'><? echo $artista; ?></font></td>
          </tr>
          
    <tr>
             <td><font face='Arial' size='2'><? echo $album; ?></font></td>
          </tr>
          
    <tr>
             <td><font face='Arial' size='2'>R$ <? echo $preco; ?></font></td>
          </tr>
          
    <tr>
             <td>
    <input type="hidden" name="txtprod[<? echo $indice;?>][CODIGO]"  value="<? echo $codigo; ?>">
    <input type="hidden" name="txtprod[<? echo $indice;?>][ARTISTA]"  value="<? echo $artista; ?>">
    <input type="hidden" name="txtprod[<? echo $indice;?>][ALBUM]"  value="<? echo $album; ?>">
    <input type="hidden" name="txtprod[<? echo $indice;?>][PRECO]"  value="<? echo $preco; ?>">
    <input type="text" name="txtprod[<? echo $indice;?>][QTDE]"  size="3" maxlength="3">  
             <input type="image" src="carrinho.gif" onClick="javascript: document.forms[0].submit();"></td>
          </tr>
          </table></td>
       <?
       //SOMA 1 A VARIÁVEL CONTROLADORA
       $atual++;
    }//FEHA FOR ?>
       </tr>
       </table>
    </form></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>

A página Carrinho.php
<?

session_start();

if($_POST[opc_atualizar]) {
   
   //RECEBE OS PRODUTOS CHECADOS PARA ATUALIZAÇÃO
   $v_atualiza  =  $_POST[a_prod];
   
   //PEGA A CHAVE DO ARRAY
   $chave  =  array_keys($v_atualiza);
   
   //EXIBE
   for($i=0; $i<sizeof($chave); $i++) {
   //PEGA O INDICE DO PRODUTO
   $indice   =   $chave[$i];
   
   //ALTERA A QUANTIDADE DO PRODUTO SELECIONADO
   $_SESSION[cesta][$indice][QTDE]   =  $v_atualiza[$indice][QTDE];
   }//FECHA FOR
}//FECHA IF


//VERIFICA SE A OPÇÃO EXCLUIR FOI SELECIONADA
elseif($_POST[opc_excluir]) {
   
   //RECEBE OS PRODUTOS CHECADOS PARA EXCLUSÃO
   $excluir  =  $_POST[check];
   
   //EXIBE
   for($i=0; $i<sizeof($excluir); $i++) {
   //PEGA O INDICE DO PRODUTO
   $indice   =   $excluir[$i];
   //DESTRÓI A VARIÁVEL ESPECIFICADA
   unset($_SESSION[cesta][$indice]);
   }//FECHA FOR
}//FECHA IF



//RECEBE O PEDIDO DO USUÁRIO
elseif($_POST[opc_efetivar]) {
   //RECEBE AS VARIÁVEIS
   $v_prod  =  $_POST[txtprod];
   
   //PEGA A CHAVE DO ARRAY
   $chave  =  array_keys($v_prod);

   //EXIBE
   for($i=0; $i<sizeof($chave); $i++) {
      $indice  =  $chave[$i];
      
      //VERIFICA
      if(!empty($v_prod[$indice][QTDE]) ) {
      
      //GRAVA NO ARRAY CESTA
      $cesta[$indice][ARTISTA]  =    $v_prod[$indice][ARTISTA];
      $cesta[$indice][ALBUM]    =    $v_prod[$indice][ALBUM];
      $cesta[$indice][PRECO]    =    $v_prod[$indice][PRECO];
      $cesta[$indice][QTDE]     =    $v_prod[$indice][QTDE];
      }//FECHA IF
   }//FECHA FOR
   
   //GRAVA NA SESSÃO
   $_SESSION[cesta]        =   $cesta;
}//FECHA ELSE
//VERIFICA SE TEM PRODUTO NO CARRINHO PARA PUXAR
  if(count($_SESSION[cesta]) > 0) { 
    //PEGA A CHAVE DO ARRAY
    $chave = array_keys($_SESSION[cesta]);

   //PEGA OS DADOS DA SESSÃO
   for($i=0; $i<sizeof($chave); $i++) { 
     //ÍNDICE
     $indice = $chave[$i]; 

    //ATRIBUI
    $cesta[$indice][ARTISTA] = $_SESSION[cesta][$indice][ARTISTA];
    $cesta[$indice][ALBUM] = $_SESSION[cesta][$indice][ALBUM];
    $cesta[$indice][PRECO] = $_SESSION[cesta][$indice][PRECO];
    $cesta[$indice][QTDE] = $_SESSION[cesta][$indice][QTDE];
  }//FECHA FOR
}//FECHA IF

?>

<html>
<head>
<title>Carrinho</title>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.style2 {
	color: #000000;
	font-weight: bold;
}
.style5 {color: #FFFFFF; font-weight: bold; }
-->
<STYLE type="text/css">
<!--
BODY {
scrollbar-face-color: #000000;
scrollbar-highlight-color: #FFFFFF;
scrollbar-3dlight-color: #C0C0C0;
scrollbar-darkshadow-color: #404040;
scrollbar-shadow-color: #808080;
scrollbar-arrow-color: #FFFFFF;
scrollbar-track-color: #FFFFFF;
}
</style>

<script language="JavaScript">
<!--
   function enviar(opcao) {
      //OPÇÃO EXCLUIR SELECIONADA
   if(opcao == 'E') {
      document.forms[0].opc_excluir.value = 1;
   document.forms[0].submit();
      }//FECHA IF
   
   //OPÇÃO ATUALIZAR SELECIONADA
   if(opcao == 'A') {
      document.forms[0].opc_atualizar.value = 1;
   document.forms[0].submit();
      }//FECHA IF
   
   //OPÇÃO FINALIZAR SELECIONADA
   if(opcao == 'F') {
      document.forms[0].opc_finalizar.value = 1;
   document.forms[0].action = "finalizar.php";
   document.forms[0].submit();
      }//FECHA IF
   
   }//FECHA FUNCTION
//-->
</script>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>

<body bgcolor="#FFCC99">
<table width="773"  border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td><br>
    <br>
    <table width="95%"  border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
          <td align='center'><div align="left"><font face='Arial' size='4'><b>Carrinho 
              de Compras</b></font></div></td>
      </tr>
    </table>
    <br>
    <br>
    <table width="95%"  border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
          <td><font size="2" face="Arial">Veja abaixo os produtos solicitados:</font></td>
      </tr>
    </table>
	
	<?
	//EXIBE O CARRINHO SE TIVER PRODUTOS
	if(count($_SESSION[cesta]) > 0) { ?>
	
    <form name="frmCarrinho" method="post">
    <input type="hidden" name="opc_excluir">
    <input type="hidden" name="opc_atualizar">
    <input type="hidden" name="opc_finalizar">
       <table width="95%"  border="0" align="center" cellpadding="0" cellspacing="0">
        <tr bgcolor="#CCCCCC">
          <td width="4%">&nbsp;</td>
          <td width="8%"><span class="style2">Qtde</span></td>
          <td width="51%"><span class="style2">Produto</span></td>
          <td width="19%"><span class="style2">Valor</span></td>
          <td width="18%"><span class="style2">Subtotal</span></td>
        </tr>
        <?
   //PEGA A CHAVE
      $chave_cesta  =  @array_keys($_SESSION[cesta]);
   
   //EXIBE OS PRODUTOS DA CESTA
   for($i=0; $i<sizeof($chave_cesta); $i++) { 
      $indice   =   $chave_cesta[$i]; 
   
   //SUBTOTAIS DE CADA PRODUTO
   $subtotal =   $_SESSION[cesta][$indice][QTDE] * ereg_replace(",",".",$_SESSION[cesta][$indice][PRECO]);
   
   //TOTAL GERAL
   $total   +=   $subtotal;
   ?>
        <tr>
          <td height="25"><input name="check[]" type="checkbox" value="<? echo $indice; ?>"></td>
          <td height="25"><font face='Arial' size='2'>
    <input type="text" name="a_prod[<? echo $indice; ?>][QTDE]" value="<? echo $_SESSION[cesta][$indice][QTDE]; ?>" size="3"></font></td>
    <td height="25"><font face='Arial' size='2'><? echo $_SESSION[cesta][$indice][ARTISTA]; ?> - <? echo $_SESSION[cesta][$indice][ALBUM]; ?></font></td>
          <td height="25"><font face='Arial' size='2'>R$ <? echo $_SESSION[cesta][$indice][PRECO]; ?></font></td>
          <td width="18%" height="25"><font face='Arial' size='2'> R$ <? echo number_format($subtotal,2,',','.'); ?></font></td>
        </tr>
        <?
   }//FECHA FOR ?>
        <tr>
          <td height="25" colspan="3">
    <input type="image" name="btnExcluir" src="excluir.gif" onClick="enviar('E');">&nbsp;&nbsp;
    <input type="image" name="btnAtualiza" src="atualizar.gif" onClick="enviar('A');"></td>
          <td height="25" bgcolor="#FF0000"><span class="style5">&nbsp;&nbsp;Total &agrave; pagar: </span></td>
          <td height="25" bgcolor="#FFF0F0" class="style2"> &nbsp;&nbsp;R$&nbsp;<b><? echo number_format($total,2,',','.'); ?></b></td>
        </tr>
        <tr>
          <td height="25" colspan="3"><div align="center"><a class="link" href="../index.htm" target="_parent">Continuar 
                Compra</a></div></td>
          <td height="40" colspan="2"><div align="center">
    <input type="image" name="btnFinaliza" src="finaliza.gif" onClick="enviar('F');"></div></td>
          </tr>
      </table>
    </form>
	<?
	}//FECHA IF(count) 
	else { ?><br><br><br>
      <table width="90%"  border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td align='center'><font face='Arial' size='2' color="#006666"><b>Desculpe, mas no momento você não possui nenhum produto.</b></td>
      </tr>
      </table><br><br>
	<?
	}//FECHA ELSE (count)?>
    <table width="70%"  border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
          <td align='center'><font face='Arial' size='2'><a href="../index.htm">&lt;&lt; 
            Voltar </a></font></td>
      </tr>
    </table>
    <br>
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>

Alguem sabe como solucionar?

Obs: *Testei em minha casa e no server não,alguem sabe como solucionar?

Obs2: Hehehehe, explicado direitnho né?
Minhas previsões estavam certas!!!
Nem todas as pessoas,com seus acidos desoxibonucleicos conseguem aprender linguagens de programação!!!
Então você iniciante,não se receie, pergunte!!!

#2 luiz000

luiz000

    Expert

  • Banidos
  • PipPipPipPipPipPip
  • 530 posts
  • Sexo:Não informado

Posted 05/06/2004, 19:39

ao inves de: $codigo = $produto[1][CODIGO];
coloca:
$codigo = $produto[1]['CODIGO'];

faça isso com TODOS

Edição feita por: luiz000, 05/06/2004, 19:46.


#3 zippy

zippy

    <?=$this->nick();?>

  • Usuários
  • 119 posts
  • Sexo:Não informado
  • Localidade:Curitiba - PR
  • Interesses:Programação<br>WebDesign

Posted 05/06/2004, 21:40

exatamente...

faça isso que o luiz falou...
['CAMPO'] ou ["CAMPO"]..

caso naum der certo, poste aqui de volta

[]s
[]s

--------------
William Grzybowski

www.linuxar.com.br (MAIS NOVO SITE SOBRE LINUX)
[tire suas duvidas sobre linux no FAQ]

www.agencialivre.com.br




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq