Questo è il codice del catalogo e del carrello.
Nel carrello non si visualizza niente; potete dirmi dove sbaglio?
catalogo.php
Codice PHP:
<?php
session_start();
include "config_db.php";
// Estrai i dati dal database
$query = "SELECT * FROM prodotti ORDER BY id_prodotto";
$res = mysql_query($query) OR DIE ("
Errore Numero: ".mysql_errno() ."
Descrizione: ". mysql_error()."<hr />");
while ($row=mysql_fetch_array($res)) {
echo '<table width="97%" border="0" cellpadding="8">';
echo '<tr style="vertical-align: middle">';
$id = $row['id_prodotto'];
$codice = $row['codice'];
$nome = $row['nome'];
$descrizione = $row['descrizione'];
$prezzo = $row['prezzo'];
echo '<td width="30%" style="text-align: center"><div align="center">';
echo $codice;
echo "</div></td>";
echo '<td width="30%" style="text-align: center"><div align="center">';
echo $nome;
echo "</div></td>";
echo '<td width="40%" style="text-align: center"><div align="center">';
echo $descrizione;
echo "</div></td>";
echo '<td width="40%" style="text-align: center"><div align="center">';
echo $prezzo;
echo "</div></td>";
echo '<td width="40%" style="text-align: center"><div align="center">';
echo "<a href=\"carrello.php?id=$id\"><img src=\"immagini/carrello.gif\" height=\"30\" width=\"30\" border=\"0\" alt=\"Inserisci questo prodotto nel carrello!\"></a>";
echo "</div></td>";
echo "</tr></table>";
}
?>
carrello.php
Codice PHP:
<?php
session_start();
$_SESSION['codice'] = $_POST['codice'];
$_SESSION['nome'] = $_POST['nome'];
$_SESSION['descrizione'] = $_POST['descrizione'];
$_SESSION['prezzo'] = $_POST['prezzo'];
for ($i = 0; $i <count($_SESSION['cart']); $i++) {
echo '<table width="97%" border="0" cellpadding="8">';
echo '<tr style="vertical-align: middle">';
echo '<td width="20%" style="text-align: center"><div align="center">';
echo ($_SESSION['codice'][$i]);
echo "</div></td>";
echo '<td width="20%" style="text-align: center"><div align="center">';
echo ($_SESSION['nome'][$i]);
echo "</div></td>";
echo '<td width="20%" style="text-align: center"><div align="center">';
echo ($_SESSION['descrizione'][$i]);
echo "</div></td>";
echo '<td width="20%" style="text-align: center"><div align="center">';
echo ($_SESSION['prezzo'][$i]);
echo "</div></td>";
echo "</tr></table>";
}
?>