Ho un grosso problema: con la mia classe (che sta per dare la maturità) abbiamo fatto un progetto semplificato di negozio on line. Purtroppo nonostante continuiamo a guardare il codice scritto non riusciamo a comprendere perché non ci salvi gli array con i codici e i prezzi degli articoli acquistati nella sessione...
Se potete aiutateci in fretta per favore perché dobbiamo consegnare il lavoro assolutamente entro questa settimana visto che ci scade la proroga ottenuta per le consegne dei lavori
Grazie a chiunque provi a guardarlo
segue copia del codice
************************************************** ***************
scaffale.php
<?php
session_start();
ob_start();
?>
<html>
<head>
<title>Scaffale articoli</title>
<style>
TH {font-family:verdana;font-size:12px,color:"#0033cc";font-weight:bold}
TD {font-family:verdana;font-size:12px,color:"#0033cc";font-weight:bold}
INPUT {font-family:verdana;font-size:14px;color:"#0033cc";background:"#FFFFCC"}
</style>
<body bgcolor="#87f4fb" text="#9900ff" link="#000000" vlink="#ff0000">
<?php
$albcod=array();
$albtit=array();
$autnome=array();
$albprez=array();
$albcopertina=array();
$albannopb=array();
$acqalbcod=array();
$acqalbprez=array();
function aggiungiCarrello($cod,$prez)
{
$z=count($acqalbcod);
$acqalbcod[$z]=$cod;
$acqalbprez[$z]=$prez;
if(!isset($_SESSION))
{
$HTTP_SESSION_VARS['articol'] = $acqalbcod;
$HTTP_SESSION_VARS['prezz'] = $acqprezz;
}
else
{
$_SESSION['articol']=$acqalbcod;
$_SESSION['prezz']=$acqalbprez;
}
}
?>
</head>
<body>
<?php
include("config.php");
$db=mysql_connect($db_host,$db_user,$db_password);
if($db==false)
die("Errore di connessione. Verifica parametri config.php");
mysql_select_db($db_name,$db)
or die ("Errore nella selezione del db. Verifica parametri config.php");
// $artista e $titolo provengono da form nella pagina precedente
if ($artista=="digita artista")
{
if ($titolo=="digita titolo")
{
header ("Location: index.html");
}
else
{
$query="SELECT albcod,albtit,autnome,albprez,albcopertina,albanno pb
FROM autori, album
WHERE (autori.autcod=album.autcod)and(albtit='$titolo')" ;
}
}
else
{
$query="SELECT albcod,albtit,autnome,albprez,albcopertina,albanno pb
FROM autori, album
WHERE (autori.autcod=album.autcod)and(autnome='$artista' )";
}
$result=mysql_query ($query,$db);
$i=0;
while($row=mysql_fetch_array($result))
{
$albcod[$i]=$row[albcod];
$albtit[$i]=$row[albtit];
$autnome[$i]=$row[autnome];
$albprez[$i]=$row[albprez];
$albcopertina[$i]=$row[albcopertina];
$albannopb[$i]=$row[albannopb];
$i=$i+1;
}
?>
<table width=100% align="center" bgcolor="#87f4fb">
<tr>
<td align="center">
<font size="5">Elenco articoli disponibili</font>
</td>
</tr>
</table>
<table width=100% bgcolor="#87f4fb" border=1>
<tr>
<th bgcolor="#CBFFFE">Album</th>
<th bgcolor="#CBFFFE">Titolo</th>
<th bgcolor="#CBFFFE">Autore</th>
<th bgcolor="#CBFFFE">Prezzo</th>
<th bgcolor="#CBFFFE">Immagine</th>
<th bgcolor="#CBFFFE">Anno</th>
<th bgcolor=lightsteelblue>Aggiungi al carrello</th>
</tr>
<?php
for ($i=0;$i<count($albcod);$i++)
{
?>
<tr>
<td bgcolor="#CBFFFE"><?=$albcod[$i]?></td>
<td bgcolor="#CBFFFE"><?=$albtit[$i]?></td>
<td bgcolor="#CBFFFE"><?=$autnome[$i]?></td>
<td bgcolor="#CBFFFE"><?=$albprez[$i]?></td>
<td bgcolor="#CBFFFE" align=center><img src=<?=$albcopertina[$i]?>border=0></td>
<td bgcolor="#CBFFFE"><?=$albannopb[$i]?></td>
<? $cod=$albcod[$i];
$prez=$albprez[$i]; ?>
<td bgcolor=lightsteelblue align=center>
<input type=button value="Aggiungi al carrello" onclick="<?aggiungiCarrello($cod,$prez)?>">
</tr>
<?php
}
?>
</table>
<center>
<input type="button" onclick="location.href='carrello.php'" value="Visualizza carrello">
</center>
</body>
</html>
************************************************** ********************
carrello.php
<?php
session_start();
ob_start();
if(!isset($_SESSION))
{
$acqalbcod=$HTTP_SESSION_VARS['articol'];
$acqalbprez=$HTTP_SESSION_VARS['prezz'];
}
else
{
$acqalbcod=$_SESSION['articol'];
$acqalbprez=$_SESSION['prezz'];
}
?>
<html>
<head>
<title>Carrello</title>
<style>
TH {font-family:verdana;font-size:12px,color:"#0033cc";font-weight:bold}
TD {font-family:verdana;font-size:12px,color:"#0033cc";font-weight:bold}
INPUT {font-family:verdana;font-size:14px;color:"#0033cc";background:"#FFFFCC"}
</style>
<body bgcolor="#87f4fb" text="#9900ff" link="#000000" vlink="#ff0000">
<?php
$totale=0;
function svuotaCarrello()
{
for ($x=0;$x<count($acqalbcod);$x++)
{
$acqalbcod[$x]="";
$acqalbprez[$x]="";
}
}
?>
</head>
<body>
<table width=100% align="center" bgcolor="#87f4fb">
<tr>
<td align="center">
<font size="5">Riepilogo acquisto</font>
</td>
</tr>
</table>
<table border=1 width=100%>
<?php
for ($z=0;$z<count($acqalbcod);$z++)
{
if ($acqalbcod[$z]!="")
{
?>
<tr>
<td bgcolor="#CBFFFE"><? echo $acqalbcod[$z]?></td>
<td bgcolor="#CBFFFE"><? echo $acqalbprez[$z]?></td>
<td bgcolor=lightsteelblue>
<input type="button" onclick=<?$acqalbcod[$z]?> location.reload(true) value="Togli dal carrello"></td>
</tr>
<input type=hidden name="<?$acqalbcod[$z]?>" value="<?$acqalbprez[$z]?>">
<?
$totale=$totale+$acqalbprez[$z];
}
}
?>
<tr><td bgcolor="#CBFFFE">Spese di spedizione</td>
<td bgcolor="#CBFFFE">10</td>
<td bgcolor=lightsteelblue></td>
</tr>
<?php
$totale=$totale+10;
$totale=($totale/100)*120;
?>
<tr>
<td bgcolor="#CBFFFE">Prezzo totale (IVA 20%)</td>
<td bgcolor="#CBFFFE"><?echo $totale?></td>
<td bgcolor=lightsteelblue></td>
</tr>
</table>
<center>
<input type=button value="Svuota carrello" onclick="svuotaCarrello()">
<input type=submit value="Acquista articoli selezionati">
</center>
<center>
<input type="button" onclick="location.href='index.html'" value="Torna a scelta articoli">
</center>
</body>
</html>