Alors, voici le code de mon catalogue:
echo "<form action=\"panier3.php\" method=\"post\">\n";
echo "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n";
echo "<tr>\n";
echo "<td width=\"65\" valign=\"top\" rowspan=\"3\">\n";
if($products["image"]<>"")
{
echo "<img src=\"produits/img_prod/".$products["image"]."\" alt=\"".StripSlashes($products["nom"])."\" border=\"0\" width='".$newwidth[0]."' height='".$newwidth[1]."'></a>\n";
}
echo "</td>\n";
echo "<td rowspan=\"3\" valign=\"top\"><IMG SRC=\"images/vertical_orange.jpg\" WIDTH=\"7\" HEIGHT=\"78\" BORDER=0 ALT=\"\"></td>\n";
echo "<td valign=\"top\" colspan=\"2\" width=\"100%\">\n";
////////////////////////////////////////////////////////
echo "<table cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">\n";
echo "<tr>\n";
echo "<td><b class=\"titre\"><input type=\"hidden\" name=\"id_produit\" value=\"".$products["id"]."\">".htmlentities(StripSlashes($products["nom"]))."</b></td>\n";
echo "</tr>\n";
if($products["description"]<>"")
{
echo "<tr>\n";
echo "<td valign=\"top\" width=\"200\">".StripSlashes($products["description"])."</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
////////////////////////////////////////////////////////
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td valign=\"top\">Prix:</td>\n";
echo "<td>\n";
////////////////////////////////////////////////////////
$sql2 = "select * from produit_format order by id ASC ";
$result2 = mysql_query($sql2);
echo "<table cellpadding=\"0\" width=\"100%\" cellspacing=\"0\">\n";
while( $row = mysql_fetch_array($result2))
{
echo "<tr>\n";
echo "<td>".$row["nom"]."</td><td>".$row["prix"]." $</td><td align=\"right\"><input type=\"radio\" name=\"format\" value=\"".$row["id"]."\"></td>\n";
echo "</tr>\n";
}
echo "</table>\n";
////////////////////////////////////////////////////////
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td align=\"right\" colspan=\"2\"><input type=\"image\" src=\"images/panier.jpg\" name=\"ajout_panier\" value=\"Ajouter\"></td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</form>\n";
Voici le code de panier qui fonctionne de panier3.php:
<?php
/* Démarrage ou prolongation de la session */
session_start();
/* On vérifie l'existence du panier, sinon, on le crée */
if(!isset($_SESSION['panier']))
{
/* Initialisation du panier */
$_SESSION['panier'] = array();
/* Subdivision du panier */
$_SESSION['panier']['id_produit'] = array();
$_SESSION['panier']['format'] = array();
}
/* Ici, on sait que le panier existe, donc on ajoute l'article dedans. */
array_push($_SESSION['panier']['id_produit'],$_POST['id_produit']);
array_push($_SESSION['panier']['format'],$_POST['format']);
?>
Voici la fonction que je ne sais pas comment appeler:
<?
function ajout($select)
{
array_push($_SESSION['panier']['id_produit'],$_POST['id_produit']);
array_push($_SESSION['panier']['format'],$_POST['format']);
}
?>
Merci!