sì ma la mia domanda è: come fare per assegnare un id univoco all'ordine? semplicemente quando l'utente conferma l'ordine, oltre ad inviare la mail, inserisco l'ordine nel database?
tipo:
Codice PHP:
<?php
session_start();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Carrello</title>
<style type="text/css">
button {
border: 1px solid #cccccc;
background: #ffffff;
}
</style>
</head>
<body>
<?php
include ("config.inc.php");
if (!isset($_SESSION['cart'])) {
echo ("Impossibile proseguire. Si è verificato un problema con le sessioni.");
exit;
} else {
foreach ( $_SESSION['cart'] as $key=>$value )
{
$prezzo=$prezzo +(($_SESSION['cart'][$key]['quantita'])*($_SESSION['cart'][$key]['prezzo']));
}
echo ("<h1>Modulo d'ordine</h1><table cellspacing=\"0\" cellpadding=\"2\" border=\"1\"><tr><td>[b]Cod. Prodotto[/b]</td><td>[b]Descrizione[/b]</td><td>[b]Prezzo Unitario[/b]</td><td>[b]Quantità[/b]</td><td>[b]Totale[/b]</td></tr>");
foreach ( $_SESSION['cart'] as $key=>$value )
{echo ("<tr><td>".$key. "</td>"
. "<td>" . $_SESSION['cart'][$key]['nome'] . "</td>"
. "<td> " . $_SESSION['cart'][$key]['prezzo'] . "</td>"
. "<td> " . $_SESSION['cart'][$key]['quantita'] . "</td>"
. "<td> " . ($_SESSION['cart'][$key]['prezzo'] * $_SESSION['cart'][$key]['quantita']). ".00</td></tr>" ) ;
}
echo ("<tr><td colspan=\"4\" align=\"right\">TOTALE</td><td>".$prezzo.".00</td></tr></table>");
echo ("
<a href=\"ordine.php?modulo=invia\">Invia modulo d'ordine</a></p>");
if (isset($_GET['modulo']) && ($_GET['modulo']=='invia')) {
$email_admin = "ordini@miosito.it";
$email = "tua@email.it";
$oggetto="Nuovo acquisto dal Nome Sito - Numero transazione";
$testo ="Ordine dal sito\n\n";
foreach ($_SESSION['cart'] as $key=>$value) {
$testo.=" Nome: ".$_SESSION['cart'][$key]['nome']."\n";
$testo.=" Prezzo ".$_SESSION['cart'][$key]['prezzo']."\n";
$testo.=" Quantità ".$_SESSION['cart'][$key]['quantita']."\n";
$testo.=" ID: ".$key."\n";
$testo.="\n\n";
}
$db = mysql_connect($db_host, $db_user, $db_password) or die("Connessione non riuscita: " . mysql_error());
$select = mysql_select_db($db_name, $db) or die ("Errore nella selezione del database. Verificare i parametri nel file config.inc.php");
$date = time();
$query = "INSERT INTO ordini (data, testo, id_user) VALUES ('$date', '$testo', '$id_user')";
$sql = mysql_query($query, $db);
mysql_close ($db);
mail($email,$oggetto,$testo,"From: ".$emailadmin."");
echo "Ordine inoltrato con successo. Entro breve tempo sarai contattato per la conferma definitiva.";
}
}
?>
</p>
</body>
</html>
ovviamente la variabile $id_user in questo script non esiste, ma nella realtà sarà una variabile recuperata tramite un pannello di login dalla tabella utenti del database.