carrello in php
-
ciao a tutti ...
sto provando a costruire un carrello con codice preso un po in rete un po' modificato da me
le pagine sono
index.php
carrello.php
funzioni.php
invioemail.php (questo e' il PROBLEMA)
mail.php(che processa il post PROBLEMA)sapete darmi una dritta per postare il tutto ad un email
funzioni.php
<?php
function usaCarrello()
{
$carrello = $_SESSION['carrello'];
if (!$carrello)
{
return 'Carrello vuoto.<br>';
}else{
$prodotti = @explode(',',$carrello);
return 'Ci sono <a href="carrello.php">'.
@count($prodotti). ' prodotti nel carrello.</a><br>';
}
}
function mostraCarrello()
{
global $db;
$carrello = $_SESSION['carrello'];
$somma = 0;
if ($carrello)
{
$prodotti = @explode(',',$carrello);
$acquisti = array();
foreach ($prodotti as $prodotto)
{
$acquisti[$prodotto] = (@isset($acquisti[$prodotto])) ? $acquisti[$prodotto] + 1 : 1;
}
$result[] = '<form action="carrello.php?action=aggiorna" method="post" id="cart">';
$result[] = '<table>';
foreach ($acquisti as $id=>$quantita)
{
$sql = 'SELECT * FROM prodotti WHERE id = '.$id;
$res = $db->query($sql);
$f = $res->fetch();
@extract($f);
$result[] = '<tr>';
$result[] = '<td><a href="carrello.php?action=cancella&id='.$id.'">Cancella</a></td>';
$result[] = '<td><br><a href="images/'.$f['immagine_orig'].'" target="_blank"><img src="images_resize/'.$f['immagine_small'].'" alt="" name="image" border="0" id="image" /></a></td>';
$result[] = '<td><br><span class="testo">'.$nome.'</span><br><span class="intestazioni">Descrizione</span><span class="testo"> :' .$marca.'</span></td>';
$result[] = '<td>€'.$prezzo.'</td>';
$result[] = '<td><input type="text" name="quantita'.$id.'" value="'.$quantita.'" size="3"></td>';
$result[] = '<td>€'.($prezzo * $quantita).'</td>';
$somma += $prezzo * $quantita;
$result[] = '</tr>';
}
$result[] = '</table>';
$result[] = 'Totale: <b><span class="tot">€'.$somma.'</span></b></br>';
$result[] = '<button type="submit">Aggiorna il carrello</button></br></br>';
$result[] = '<a href="invio_email.php?action=ordina&id='.$f['id'].' ">ORDINA</a>';
$result[] = '</form>';
}else{
$result[] = 'Carrello vuoto.<br>';
}
return @join('',$result);
}
?><?php
//aggiunte per vedere i prodotti ordinati in invioemail.php
function riassunto()
{
$carrello = $_SESSION['carrello'];
if (!$carrello)
{
return 'Carrello vuoto.<br>';
}else{
$prodotti = @explode(',',$carrello);
return 'Stai acquistando :'.
@count($prodotti). ' prodotti.</a><br>';
}
}
function riassunto_1()
{
global $db;
$carrello = $_SESSION['carrello'];
$somma = 0;
if ($carrello)
{
$prodotti = @explode(',',$carrello);
$acquisti = array();
foreach ($prodotti as $prodotto)
{
$acquisti[$prodotto] = (@isset($acquisti[$prodotto])) ? $acquisti[$prodotto] + 1 : 1;
}
$result[] = '<form action="carrello.php?action=aggiorna" method="post" id="cart">';
$result[] = '<table>';
foreach ($acquisti as $id=>$quantita)
{
$sql = 'SELECT * FROM prodotti WHERE id = '.$id;
$res = $db->query($sql);
$f = $res->fetch();
@extract($f);
$result[] = '<tr>';
$result[] = '<td><span class="testo">'.$nome.'</span></td>';
$result[] = '<td>€'.$prezzo.'</td>';
$result[] = '<td><input type="text" name="quantita'.$id.'" value="'.$quantita.'" size="3"></td>';
$result[] = '<td>€'.($prezzo * $quantita).'</td>';
$somma += $prezzo * $quantita;
$result[] = '</tr>';
}
$result[] = '</table>';
$result[] = 'Totale: <b><span class="tot">€'.$somma.'</span></b></br>';
$result[] = '</form>';
}else{
$result[] = 'Carrello vuoto.<br>';
}
return @join('',$result);
}
?>invioemail.php
<form name="form1" method="post" action="mail.php">
<table width="523" align="center" cellpadding="3" >
<tr>
<td colspan="2" align="center"><table width="176" border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="182" class="testo"> </td>
</tr>
</table></td>
</tr>
<tr>
<td width="23%" align="right"><strong class="testo">Nome :::</strong></td>
<td><input name="nome" type="text" class="form" size="40"></td>
</tr>
<tr>
<td align="right"><strong class="testo">Cognome :::</strong></td>
<td><input name="cognome" type="text" class="form" size="40"></td>
</tr>
<tr>
<td align="right"><strong class="testo">Localita' ::: </strong></td>
<td><input name="localita" type="text" class="form" id="localita" size="40"></td>
</tr>
<tr>
<td align="right"><strong class="testo"> Email ::: </strong></td>
<td><input name="email" type="text" class="form" id="email" size="40"></td>
</tr>
<tr>
<td align="right" class="testo">Indirizzo:::</td>
<td><input name="indirizzo" type="text" class="form" size="60" id="indirizzo" /></td>
</tr>
<tr>
<td align="right"><strong class="testo">Cap :::</strong></td>
<td><input name="cap" type="text" class="form" size="25" id="cap"></td>
</tr>
<tr>
<td align="right"><strong class="testo">Telefono :::</strong></td>
<td><input name="telefono" type="text" class="form" size="40" id="telefono" /></td>
</tr>
<tr>
<td align="right"> </td>
<td class="testo">metodo di pagamento : contrassegno</td>
</tr>
<tr>
<td colspan="2"><table width="324" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td colspan="3" align="center"><p><span class="privacy">Si accetto condizioni sulla privacy dei dati : </span>
<input name="si" type="radio" value="si" />
<br />
<br />
</p> </td>
</tr>
<tr>
<td width="68" align="right" class="testo"> </td>
<td width="45"><label></label></td>
<td width="165"><label></label></td>
</tr></table></td>
</tr>
<tr>
<td height="40" colspan="2"><div align="center">
<table width="381" border="0" align="left" cellpadding="2" cellspacing="0">
<tr>
<td width="214" align="right"><input name="Submit" type="submit" class="pulsanti" value="Invia modulo" onclick="return checkData()" /></td>
<td width="30"> </td>
<td width="125"><label>
<input name="Submit2" type="reset" class="pulsanti" value="Ripristina modulo" />
</label></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td height="40" colspan="2">Riassunto merce comprata :<br />
<?php
@session_start();
@require('mysql.php');
@require('config.php');
@require('funzioni.php');
//le due funzioni create
?>
<?php
echo riassunto();
?>
<?php
echo riassunto_1();
?>
<a href="index.php">Torna allo shop</a><br />
<br /></td>
</tr>
</table>
</form>mail.php
<?php
// L'INDIRIZZO DEL DESTINATARIO DELLA MAIL
$to = "info......it";
// IL SOGGETTO DELLA MAIL
$subject = "*Modulo proveniente dal sito xxx.mar.it";
// COSTRUZIONE DEL CORPO DEL MESSAGGIO
$body = "Contenuto:\n\n";
$body .= "Dati personali ;<br>nome: " . trim(stripslashes($_POST["nome"])) . "\n";
$body .= "cognome: " . trim(stripslashes($_POST["cognome"])) . "\n";
$body .= "Localita': " . trim(stripslashes($_POST["localita"])) . "\n";
$body .= "Email: " . trim(stripslashes($_POST["email"])) . "\n";
$body .= "Indirizzo: " . trim(stripslashes($_POST["indirizzo"])) . "\n";
$body .= "Cap: " . trim(stripslashes($_POST["cap"])) . "\n";
$body .= "Telefono: " . trim(stripslashes($_POST["telefono"])) . "\n";
$body .= "si: " . trim(stripslashes($_POST["si"])) . "\n";
$result .= "nome: " . trim(stripslashes($_POST['nome'])) . "\n";
$result .= "prezzo: " . trim(stripslashes($_POST['prezzo'])) . "\n";
$result .= "quantita': " . trim(stripslashes($_POST['quantita'])) . "\n";
$somma= "somma: " . trim(stripslashes($_POST['prezzo' * 'quantita'])) . "\n";
// queste non sono assolutamente sicuro.....
if(@mail($to, $subject, $body,$result,$somma))
?>grazie dell'aiuto.....





-
ok ho tentato di arrangiarmi da solo.....
e qualche cosa mi e' uscito
posto il file a beneficio di tutti se interessa....http ecc w14.easy-share.com/1701142866.html
se volete svilupparlo e segnalarmi le migliorie....
io sono qui'
thanks
Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.
Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.
Con il tuo contributo, questo post potrebbe essere ancora migliore 💗
Registrati Accedi