Tout d'abord bonjour à tous.
J'éspère que vous pourrez m'aider car la je séche un peu.
Voici mon problème j'ai code un simili panier très simple le problème est que lorsque je clique sur ajouter au panier dans mon panier il n'y a jamais le produit choisis mais toujours un autre ( c'est ce qu'on appelle de la vente forçée mdr

)
Voici mon code
Fonction panier dans include <?php
// on se connecte à notre base
$id5 = $_POST['idpanier'];
$base = mysql_connect ();
mysql_select_db ();
// on prépare une requête permettant de calculer le nombre total d'éléments qu'il faudra afficher sur nos différentes pages
$sql = "SELECT * FROM immobilier WHERE id='".$id5."'";
$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
$data = mysql_fetch_array($req);
if (isset($_POST['panier']) && $_POST['panier']=='Ajouter')
{
$reference=$data['ref'];
$nb=1; //par défaut la quantité est = 1
$prix=$data['budget'];
if(!isset($liste[$id5]))
$liste[$id5]=array($reference,$nb,$prix);
$_SESSION['liste']=$liste;
}
?>
Ajout au panier<form action="#" method="post"><div style="display:none; visibility:hidden"><input type="text" name="idpanier" value="' , $data['id'] , '"/></div> <input type="image" name="panier" src="./img/boutons/ajout.gif" value="Ajouter" /></form>
Le Panier<?php
// on se connecte à notre base
$base = mysql_connect ();
mysql_select_db ();
if ($liste <= 0)
{
echo '<tr bgcolor="#ffec90"><td valign="middle" align="center" height="400">
<span class="titre2"> Votre panier est vide</span></td></tr>
<tr bgcolor="#ffec90"><td colspan="3" height="24" align="center" background="./img/bcriteres.png"> </td></tr>';
}
else
{
for ($i=0;$i<count($liste);$i++)
{
$sql = 'SELECT * FROM immobilier WHERE id ="'.$liste[$i][0].'" ORDER BY id ASC';
// on exécute la requête
$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
// on va scanner tous les tuples un par un
$data = mysql_fetch_assoc($req);
// on affiches les résultats dans la <table>
echo '<tr bgcolor="#ffec90"><td valign="top"><table width="500" border="0" align="center" cellpadding="0" cellspacing="0" style="border: solid #ff8600 1px">
<tr bgcolor="#ffec90" height="36">
<td colspan="2" class="titrebien"> ' , htmlentities(trim($data['type'])) , ' ' , htmlentities(trim($data['transaction'])) , ' à ' , stripslashes ( htmlentities(trim($data['ville']))) , ' (' , htmlentities(trim($data['dept'])) , ') </td>
<td align="right" style="color:red; font-weight:bold; font:16px;">' , htmlentities(trim($data['budget'])) , ' € </td>
</tr>
<tr bgcolor="#ffec90" height="36">
<td width="135" rowspan="3" align="center">';
if ($data['image'] == '') {
echo '<img src="./img/image2.gif" width="100" height="100" border="0">';
}
else {
echo '<img src="./img/biens/' , htmlentities(trim($data['image'])) , '" height="100" width="100" border="0" />';
}
echo '</td><td width="400"><span class="recherche" style="font-weight:bold">Référence :</span> ' , htmlentities(trim($data['ref'])) , ' </td>
<td width="75" class="recherche" > </td>
</tr>
<tr bgcolor="#ffec90">
<td width="400" valign="top"><span class="recherche" style="font-weight:bold">Contact :</span> ' , htmlentities(trim($data['contact'])) , '</td>
<td class="recherche"> </td>
</tr>
<tr bgcolor="#ffec90">
<td><div align="justify">'.substr(''.stripslashes (htmlentities(trim($data['description']))).'', 0, 150).'...</div></td>
<td class="recherche"> </td>
</tr>
<tr bgcolor="#ffec90" height="36">
<td colspan="3" align="center" class="recherche"><a href="index.php?page=id9&ref='.htmlentities(trim($data['id'])).'"><img src="./img/boutons/savoir.jpg" alt="En savoir +" height="20" border="0" /></a></td>
</tr>
</table><br></td></tr><tr>';
}
// on libère l'espace mémoire alloué pour cette requête
mysql_free_result ($req);
// on affiche enfin notre barre
echo '<td colspan="3" height="24" align="center" background="./img/bcriteres.png"> </td>';
}
// on ferme la connexion à la base de données.
mysql_close ();
?>
Merci d'avance pour votre aide