Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá galera estou inciando a jornada em php :ermm: , e pelo pouco de conhecimento que tenho estou com dificuldades em solucionar uma situação que acredito que para muitos é simples, e então la vai o scrpits (o que ocorre é que ele busca as informações gravadas em um BD e disponibiliza como produtos para efetuar a compra e preciso que seja enviado as informações por email , até ai td ok consigo enviar por email sem problemas , mas ele envia somente a ultima linha da compra , não estou conseguindo fazer o loop para enviar no email ....) :( preciso de um help: (todos os scripts estão OK o detalhe e no arquivo
finalizando.php que não consigo criar o loop para enviar todas informações).....
inicio.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=iso-8859-1" />
<title>Video Aula sobre Carrinho de Compras</title>
<style type="text/css"> </style>
</head>
<body><table width="450" border="0" cellspacing="0" cellpadding="0" id="layer">
<tr>
<td align="center"><h1>Minha Loja</h1></td>
</tr>
<tr>
<td><div id="layer" >
<?php
$conexao = mysql_connect ('localhost','cosmetic_beauty','foa1ko02');
$db = mysql_select_db ('cosmetic_beauty');
?>
<?php
$sql = "SELECT * FROM beauty_loja";
$qr = mysql_query($sql) or die(mysql_error());
while($ln = mysql_fetch_assoc($qr)){
echo '<ul>';
echo '<li><h2>'.$ln['nome'].'</h2> </li>';
echo '<li><img src="beauty-loja/'.$ln['imagem'].'" style="width:100px; height:80ppx;" /></li> ';
echo '<li> <h3>Preço : R$ '.number_format($ln['preco'], 2, ',', '.').'</h3></li>';
echo '<li><a href="index.php?page=carrinho_beauty&acao=add&id='.$ln['id'].'"><img src="images/botao.png" /></a></li>';
echo '</ul>';
}
?>
</div></td>
</tr>
</table>
</body>
</html>
carrinho.php
<?php
session_start();
if(!isset($_SESSION['carrinho'])){
$_SESSION['carrinho'] = array();
}
if(isset($_GET['acao'])){
if($_GET['acao'] == 'add'){
$id = intval($_GET['id']);
if(!isset($_SESSION['carrinho'][$id])){
$_SESSION['carrinho'][$id] = 1;
}else{
$_SESSION['carrinho'][$id] += 1;
}
}
if($_GET['acao'] == 'del'){
$id = intval($_GET['id']);
if(isset($_SESSION['carrinho'][$id])){
unset($_SESSION['carrinho'][$id]);
}
}
if($_GET['acao'] == 'up'){
if(is_array($_POST['prod'])){
foreach($_POST['prod'] as $id => $qtd){
$id = intval($id);
$qtd = intval($qtd);
if(!empty($qtd) || $qtd <> 0){
$_SESSION['carrinho'][$id] = $qtd;
}else{
unset($_SESSION['carrinho'][$id]);
}
}
}
}
}
?>
<!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>Video Aula sobre Carrinho de Compras</title>
<style type="text/css">
<!--
#carrinho { font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; color:#CCC;}
#carrinho a {color:#9F0; font-weight:bold;}
#carrinho a:hover{color:#C90; font-weight:bold;}
carrinho h1{color:#39F; font:"Trebuchet MS", Arial, Helvetica, sans-serif;}
-->
</style>
</head>
<body>
<table id="carrinho">
<caption><h1>Meus Produtos</h1></caption>
<thead>
<tr>
<th width="198" >Produto</th>
<th width="88" >Qtde</th>
<th width="98" >Preço</th>
<th width="93" >SubTotal</th>
<th width="104" >Remover</th>
</tr>
</thead>
<form action="index.php?page=carrinho_beauty&acao=up" method="post">
<tfoot>
<tr>
<td colspan="5" align="center"><input type="submit" value="Atualizar Carrinho" /></td>
<tr>
<td colspan="5" align="center"> </td>
<tr>
<td colspan="2" align="center"><a href="index.php?page=cliente_beauty">Continuar Comprando</a></td>
<td colspan="3" align="center"><a href="index.php?page=finalizando_beauty">Encerrar Minha Compra</a></td>
</tfoot>
<tbody id="carrinho">
<?php
$conexao = mysql_connect ('localhost','cosmetic_beauty','foa1ko02');
$db = mysql_select_db ('cosmetic_beauty');
?>
<?php
if(count($_SESSION['carrinho']) == 0){
echo '<tr><td colspan="5">Não há produto no carrinho</td></tr>';
}else{
$total = 0;
foreach($_SESSION['carrinho'] as $id => $qtd){
$sql = "SELECT * FROM beauty_loja WHERE id= '$id'";
$qr = mysql_query($sql) or die(mysql_error());
$ln = mysql_fetch_assoc($qr);
$nome = $ln['nome'];
$preco = number_format($ln['preco'], 2, ',', '.');
$sub = number_format($ln['preco'] * $qtd, 2, ',', '.');
$total += $ln['preco'] * $qtd;
echo '<tr>
<td>'.$nome.'</td>
<td><input type="text" size="3" name="prod['.$id.']" value="'.$qtd.'" /></td>
<td>R$ '.$preco.'</td>
<td>R$ '.$sub.'</td>
<td><a href="index.php?page=carrinho_beauty&acao=del&id='.$id.'">Remove</a></td>
</tr>';
}
$total = number_format($total, 2, ',', '.');
echo '<tr>
<td colspan="4">Total</td>
<td>R$ '.$total.'</td>
</tr>';
}
?>
</tbody>
</form>
</table>
</body>
</html>
finalizando.php
<?php
session_start();
if($_POST[opc_enviar]) {
$v_nome = $_POST[txtNome];
$v_end = $_POST[txtEndereco];
$v_email = $_POST[txtEmail];
$qtd = $_POST[qtd];
$nome = $_POST[nome];
$preco = $_POST[preco];
$sub = $_POST[sub];
$total = number_format($_POST[total],2,',','.');
$email_dest = "andreroberto2004@yahoo.com.br";
$mens = "----------------------------------------------------------------------\n";
$mens .= " Cosmetic Beauty \n";
$mens .= " Pedido de Compras \n";
$mens .= "--------------------------------------------------------------------\n\n";
$mens .= "Qtde Descrição Valor Unit. Sub Total \n";
$mens .= "------------------------------------------------------------------------\n";
$mens .= " \n";
$mens .= " ".$qtd." ".$nome." ".$preco." R$ ".$sub." \n";
$mens .= " \n\n";
$mens .= "DADOS PARA ENTREGA: \n";
$mens .= "Nome: ".$v_nome." \n";
$mens .= "Endereço: ".$v_end." \n";
$mens .= "Email: ".$v_email." \n\n";
$mens .= "Obrigado!! \n";
$mens .= "Cosmetic Beauty ";
$envia = mail($email_dest, "Cosmetic Beauty", $mens,"From:".$v_email."\r\nBcc:".$v_email);
if($envia) {
$_SESSION = array();
@session_destroy(); ?>
<script language="JavaScript">
<!--
alert("PARABÉNS!!\n\nO seu pedido foi enviado com sucesso.");
window.location.href = "index.php?page=cliente_beauty";
//-->
</script>
<?
}
else {?>
<script language="JavaScript">
<!--
alert("ERRO!!\n\nAconteceu algum problema.\n\nPor favor, tente novamente...");
window.location.href = "index.php?page=cliente_beauty";
//-->
</script>
<?
}
}
?>
<html>
<head>
<title>Beauty</title>
<style type="text/css">
<!--
#carrinho { font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; color:#CCC;}
#carrinho a {color:#9F0; font-weight:bold;}
#carrinho a:hover{color:#C90; font-weight:bold;}
#carrinho h1{color:#FFC; font:"Trebuchet MS", Arial, Helvetica, sans-serif; font-size:18px;}
-->
</style>
<script language="JavaScript">
<!--
function finaliza() {
if(confirm('Deseja mesmo efetivar esse pedido ?'))
return true;
else return false;
}//FECHA FUNCTION
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body>
<table width="350" border="0" cellspacing="0" cellpadding="0" id="carrinho">
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td colspan="2" align="center"><h1>" Minha Compra "
</h1></td>
</tr>
<td height="20"> <tr>
<form name="frmFinalizar" method="post" onSubmit="return finaliza();">
<?php
$conexao = mysql_connect ('localhost','cosmetic_beauty','foa1ko02');
$db = mysql_select_db ('cosmetic_beauty');
?>
<?php
if(count($_SESSION['carrinho']) == 0){
echo '<tr><td colspan="5">Não há produto no carrinho</td></tr>';
}else{
$total = 0;
foreach($_SESSION['carrinho'] as $id => $qtd){
$sql = "SELECT * FROM beauty_loja WHERE id= '$id'";
$qr = mysql_query($sql) or die(mysql_error());
$ln = mysql_fetch_assoc($qr);
$nome = $ln['nome'];
$preco = number_format($ln['preco'], 2, ',', '.');
$sub = number_format($ln['preco'] * $qtd, 2, ',', '.');
$total += $ln['preco'] * $qtd;
echo '
<input type="text" name="qtd" value="'.$qtd.' ">
<input type="text" name="nome" value="'.$nome.'">
<input type="text" name="preco" value=" R$ '.$preco.'">
<input type="text" name="sub" value=" R$ '.$sub.'">
<input type="hidden" name="opc_enviar" value=" "> <br>
';
}
$total = number_format($total, 2, ',', '.');
echo '<tr>
<td colspan="4">Total</td>
<td>R$ '.$total.'</td>
</tr>';
}
?>
<td>
<tr>
<td colspan="2" align="center"> </td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="text" name="total" value="<? echo $total; ?>">
<input name="btnEnviar" type="submit" value="Finalizar Compra >>">
</form></td>
</tr>
<tr>
<td colspan="2" align="center"> </td>
</tr>
<tr>
<td colspan="2" align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="54%" align="center"><a href="index.php?page=cliente_beauty"><< Carrinho de compras </a></td>
<td width="46%" align="center"><a href="index.php?page=carrinho_beauty"> Meus Produtos >></a></td>
</tr>
</table></td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"> </td>
</tr>
</table>
</body>
</html>Carregando comentários...