|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Apr 2005
Messaggi: 5245
|
[PHP] Inserimento tabella in script
questo è un piccolo script che permette una volta aggiunti dei prodotti, di visualizzarli in una tabella. Questi posso essere acquistati e verrà inviata un mail con il riepilogo.
Adesso allo stato attuale va tutto alla grande. Gli unici problemi che riscontro sono: + Quando chiedo di inserire i dati per l'acquisto non mi visualizza i prodotto messi nel carrello + Quando arriva la mail non mi visualizza i prodotti messi nel carrello Di seguito vi posto i codici: Funzioni.php Codice:
<?php
function top(){
echo "<html>
<head>
<title>Acquisto prodotti</title>
</head>
<body>
<div align=\"center\">
<table width=\"903\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\" bgcolor=\"#ffffff\">
<tr>
<td width=\"200\" align=\"center\" valign=\"top\" bgcolor=\"#ffffff\">
<iframe width=\"198\" marginwidth=\"0\" marginheight=\"2\" src=\"login.php\" name=\"main\" frameborder=\"0\" scrolling=\"no\" height=\"150\">
</iframe></td>
<td colspan=\"6\" align=\"center\" valign=\"top\" bgcolor=\"#ffffff\">";
}
function bottom(){
echo "</td>
</tr></table></body>
</html>";
}
function usaCarrello()
{
$carrello = $_SESSION['carrello'];
if (!$carrello)
{
return 'Il 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 border="1" frame="border" rules="none" width="75%" align="center">';
$result[] = '<tbody><tr>';
// $result[] = '<td width="15%"><b>CODICE</b></td>';
// $result[] = '<td width="20%"><b>CATEGORIA</b></td>';
$result[] = '<td width="15%"><b>MARCA</b></td>';
$result[] = '<td width="20%"><b>DESCRIZIONE</b></td>';
$result[] = '<td width="50%"><b>PREZZO</b></td>';
$result[] = '<td width="50%"><b>Q.TA</b></td>';
$result[] = '<td width="50%"><b>IMPORTO</b></td>';
$result[] = '</tr>';
$result[] = '<tr>';
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>'.$nome.'</td>';
$result[] = '<td>'.$marca.'</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[] = '<td><a href="carrello.php?action=cancella&id='.$id.'">ELIMINA</a></td>';
$result[] = '</tr>';
}
$result[] = '</table>';
$result[] = 'Totale: <b>€'.$somma.'</b></br>';
$result[] = '<button type="submit">Aggiorna il carrello</button>';
$result[] = '</form>';
}else{
$result[] = 'Il carrello è vuoto.<br>';
}
return @join('',$result);
}
?>
<style type="text/css">
<!--
input,select {
border: 1px solid nero;
background-color: #f2ffd5;
font-size: 16px;
font-family: Helvetica;
color: #blu;
}
h1{
font-family: Verdana,arial;
color: #000000;
}
table{
background: #f2ffd5;
border: 2px ridge #FF9224;
}
body {margin-top: 4px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;font-size: 20px; font-family: Helvetica, Arial, Verdana; background-color: #216383}
thead{
font-family: verdana, Times, serif;
text-align: center;
color: #669933;
background: white;
}
td,th {font-family: Times New Roman; font-size: 10px; border: 0px }
a:link { font-family: Helvetica, Arial, Verdana; font-size: 15px; font-weight: bold; color: #CC6600 ; text-decoration: none; text-align: center }
a:visited {font-family: Helvetica, Arial, Verdana; font-size: 15px; font-weight: bold; color: #CC6600 ; text-decoration: none; text-align: center}
a:hover {
color: #000000;
}
a:active {
color: #FF0000;
}
img {
border: 0px;
}
div {
text-align: center;
}
-->
</style>
ordine.php Codice:
<?php
@require('funzioni.php');
top();
?>
<form action="confermaordine.php" method="post" enctype="multipart/form-data">
<h1>Inserire i dati nel form sottostante:</h1>
<table width="400" border="1" cellspacing="0" cellpadding="0">
<tr>
<td><b>COGNOME:</b></td>
<td><input name="cognome" type="text" size="25" maxlength="25"></td>
</tr>
<tr>
<td><b>NOME:</b</td>
<td><input name="nome" type="text" size="25" maxlength="25"></td>
</tr>
<tr>
<td><b>RAGIONE SOCIALE:</b</td>
<td><input name="ragionesociale" type="text" size="25" maxlength="25"></td>
</tr>
<tr>
<td><b>PARTITA IVA/CODICE FISCALE:</b</td>
<td><input name="cod_part" type="text" size="25" maxlength="25"></td>
</tr>
<td><b>INDIRIZZO:</b</td>
<td><input name="indirizzo" type="text" size="25" maxlength="50"></td>
</tr>
<tr>
<td><b>LOCALITA' (PROV):</b</td>
<td><input name="localita" type="text" size="25" maxlength="25"></td>
</tr>
<tr>
<td><b>CAP:</b</td>
<td><input name="cap" type="text" size="25" maxlength="5"></td>
</tr>
<tr>
<td><b>EMAIL:</b</td>
<td><input name="email" type="text" size="25" maxlength="25"></td>
</tr>
<tr>
<td><b>TELEFONO:</b</td>
<td><input name="telefono" type="text" size="25" maxlength="25"></td>
</tr>
</table>
<br>
<br>
<a href="index.php"><img src="btn_backshop.gif\"></a>
<input name="invia il modulo" type="image" src="btn_confermaordine.gif">
</form>
</body>
</html>
<?php bottom(); ?>
confermaordine.php Codice:
<?php
$msg ="Ciao Utente ";
$msg .= "\n";
$msg .= "\n";
$msg .= "\n";
$msg .= $_POST['cognome'];
$msg .= "\n";
$msg .= $_POST['nome'];
$msg .= "\n";
$msg .= $_POST['ragionesociale'];
$msg .= "\n";
$msg .= $_POST['indirizzo'];
$msg .= "\n";
$msg .= $_POST['localita'];
$msg .= "\n";
$msg .= $_POST['email'];
$msg .= "\n";
$msg .= $_POST['telefono'];
$msg .= "\n";
$msg .= $_POST['cod_part'];
$msg .= "\n";
if (trim($cognome)=="" or trim($nome)=="" or trim($ragionesociale)=="" or trim($indirizzo)=="" or trim($localita)=="" or trim($email)=="" or trim($telefono)=="" or trim($cod_part)=="") {
echo "I campi obbligatori devono essere riempiti...torna indietro";
}else if(!$risultato = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $email)){
echo " <b>$email</b> non è un indirizzo email valido";
}
else{
// permetto anche l'inserimento del simbolo ' es: l'altra volta...
$cognome=addslashes(stripslashes($cognome));
$nome=addslashes(stripslashes($nome));
$ragionesociale=addslashes(stripslashes($ragionesociale));
$indirizzo=addslashes(stripslashes($indirizzo));
$localita=addslashes(stripslashes($localita));
$email=addslashes(stripslashes($email));
$telefono=addslashes(stripslashes($telefono));
$cod_part=addslashes(stripslashes($cod_part));
// setto il primo carattere in maiuscolo
$cognome=ucfirst($cognome);
$nome=ucfirst($nome);
$header = "From:<[email protected]>\n";
$header .= "Reply-To:<[email protected]>\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$header .= "Content-Transfer-Encoding: 7bit\n\n";
$msg = "<html><body bgcolor=black>
<center><table width=\"803\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=orange>
<tr>
<td><font color=orange><p align=\"left\"><br>Ciao <b>$cognome $nome</b>, Stealk è felice di darti il suo benvenuto
<br><p align=\"justify\">Portando a termine l'iscrizione potrai subito acquistare i nostri prodotti effettuando il login<br>
Per effettare il login basta inserire la username e la password da te scelte negli appositi campi della sezione situata nella colonna sinistra<br>
<br>
<br>
<b>DATI PER LA SPEDIZIONE</b><br>
<br>
COGNOME:<b>$cognome</b><br>
NOME:<b>$nome</b><br>
RAGIONE SOCIALE:<b>$ragionesociale</b><br>
PARTITA IVA/CODICE FISCALE:<b>$cod_part</b><br>
INDIRIZZO:<b>$indirizzo</b><br>
LOCALITA:<b>$localita</b><br>
EMAIL:<b>$email</b><br>
TELEFONO:<b>$telefono</b><br>
<br>
Per non perdere i dati ti consiglio di non cancellare questa email
<br><br>Per completare l'iscrizione non ti resta che cliccare nel collegamento sottostante...Se
il collegamento non funziona, copia l'URL e incollala nella barra degli indirizzi del tuo browser(Internet explorer, firefox)<br>
<br><p align=\"center\">
<p align=\"right\">
Cordiali saluti<br>
<i>Stealk</i>
</font>
</td>
</tr></table><hr>";
$subject = "Acquisto Prodotti";
mail("[email protected]", $subject, $msg, $header );
header("Refresh: 2; URL=http://www.xxxorg/m/email_inviata.html");
}
?>
Poteta aiutarmi?? Grazie |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 01:41.



















