partie du code de la page index:
Code PHP :
<form name='ajout_panier' action='adcos.php' method='POST'>
<input type="hidden" name="idcab" id="idcab" value="1">
<table border='0'>
<tr>
<td align="right"><input type='text' maxlength='2' size='1' value='1' name='QTE'></td>
<td align="left"><a href=javascript:Maj_qte(1);><img border='0' name='qte_plus' src='images/qte_plus.gif' title='Augmenter la quantité' alt='Augmenter la quantité'/></a><br>
<a href=javascript:Maj_qte(-1);><img border='0' name='qte_moins' src='images/qte_moins.gif' title='Diminuer la quantité' alt='Diminuer la quantité'/></a></td></tr>
<tr>
<td colspan="2">
<input type='image' src='images/AjouterPanier.gif' title="Ajouter l'article à votre panier" alt="Ajouter l'article à votre panier"/></td>
</tr>
</table>
</form>
le cod du fichier adcos.php
Code PHP :
<?php
include("connect.php");
for($i=0; $i<$_POST[QTE]; $i++)
{
$_SESSION['products'][] = $_POST['idcab'];
}
echo "Le produit est dans le panier";
function getcart(){
if(!count($_SESSION['products']))
echo "<table cellspacing='5' cellpadding='5'>
<tr>
<td id='info'>Pas de produits dans le panier!</td>
</tr>
</table>";
else{
$total = 0;
foreach(array_count_values($_SESSION['products']) as $cleu=>$valu){
$result=mysql_query("select * from vin where id='$cleu'");
$row=mysql_fetch_array($result);
echo "<table cellspacing='5' cellpadding='5' style='border-top: 1px solid #0072aa;'>";
$id = $row['id'];
$product = $row['product'];
$company = $row['company'];
$price = $row['price'];
$urlimage = $row['urlimage'];
$prixu = $price*$valu;
$total += $prixu;
echo "<tr>
<td rowspan='4'>
<img src=\"images/$urlimage\" alt=\"$product\" align=\"center\" width='75'></td>
<td id='product' width='800'>$product</td>
</tr>
<tr><td>Quantite : $valu</td></tr>
<tr>
<td id='company'>by $company</td>
</tr>
<tr>
<td id='price'>Prix unitaire: $price</td>
</tr>
<tr>
<td id='price'>Prix : $prixu</td>
</tr>
<tr>
<td colspan='2' align='center'><a href='suparticle.php?id=$id' class='link'>Supprimer</a></td>
</tr>";
echo "</table>";
}
echo "<table align='center'><tr><td colspan='2' id='total' align='center'>Prix total: ".$total."</td></tr></table>";
}
}
getcart();
?>
codu du suparticle.php
Code PHP :
<?php
include("connect.php");
$id=$_GET[id];
unset($_SESSION['products'][$id]);
function getcart(){
if(!count($_SESSION['products']))
echo "<table cellspacing='5' cellpadding='5'>
<tr>
<td id='info'>Nu sunt produse in cos!</td>
</tr>
</table>";
else{
$total = 0;
foreach(array_count_values($_SESSION['products']) as $cleu=>$valu){
$result=mysql_query("select * from vin where id='$cleu'");
$row=mysql_fetch_array($result);
echo "<table cellspacing='5' cellpadding='5' style='border-top: 1px solid #0072aa;'>";
$id = $row['id'];
$product = $row['product'];
$company = $row['company'];
$price = $row['price'];
$urlimage = $row['urlimage'];
$prixu = $price*$valu;
$total += $prixu;
echo "<tr>
<td rowspan='4'>
<img src=\"images/$urlimage\" alt=\"$product\" align=\"center\" width='75'></td>
<td id='product' width='800'>$product</td>
</tr>
<tr><td>Quantite : $valu</td></tr>
<tr>
<td id='company'>by $company</td>
</tr>
<tr>
<td id='price'>Prix unitaire: $price</td>
</tr>
<tr>
<td id='price'>Prix : $prixu</td>
</tr>
<tr>
<td colspan='2' align='center'><a href='suparticle.php?id=$id' class='link'>Sterge</a></td>
</tr>";
echo "</table>";
}
echo "<table align='center'><tr><td colspan='2' id='total' align='center'>Prix total: ".$total."</td></tr></table>";
}
}
getcart();
?>
Merci de votre aide