8791 sujets

Développement web côté serveur, CMS

J'ai un petit souci j'ai un panier auquel je voudrai laisser l'utilisateur remplir sa quantite le probleme c'est que lorsque il y a plusieur article seul la derniere valeur saisie dans le champ text es reprise pour tout les produits.


<?php
if (isset($_SESSION["caddie"])) 
{ 
$caddie = $_SESSION["caddie"]; 
} 
else 
{ 
$caddie = array(); 
} 

if (isset($sup)) 
{ 
unset($caddie["$sup"]); 
} 
$nombre = $_POST["qte"]; 
$quantite = array ($nombre) ;
?>

<table width="900" border="0" align="center"> 
<tr align="center"> 
<td width="60%" align="left"><strong>Intitul&eacute; 

</strong></td> 
<td width="20%" align="left"><strong>Quantit&eacute; </strong></td> 
<td width="20%"><strong>Supprimer</strong></td> 
</tr></table>

<?php 
while($var = each($caddie)) 
{ 
$sql = "SELECT * FROM produit WHERE IDProduit='".$var[0]."'"; 
$sql = mysql_db_query($base,$sql); 
while ($site=mysql_fetch_array($sql)) 
{ 

echo "<table width='900px' align='center'> 
<tr> 
<td width='60%'$site[LibelleProd]</td> 
<td width='20%' align=\"left\"> 
<form action=\"commande.php\" method=\"post\"> 
<input type=\"text\" name=\"qte\" value=\"1\"size=\"2\" maxlength=\"2\"> 
</td> 

<td width='20%' align='center'><a href=\"panier.php?sup=$site[IDProduit]\"><img src=\"img/supprimer.gif\" border=\"0\"onclick=\"javascript:if(!confirm('Etes-vous sûr de vouloir supprimer cet article de votre panier?')) return false;\" ></a></td> 
</tr> 
</table> 
</td> 
</tr>"; 
} 
} 
echo"<center><table border=\"0\" cellpadding=10 > 
<tr> 
<td><td ><input name=\"devis\" type=\"radio\" value=\"Demande de devis\" /><b>Demande de devis </b></td><td >
<input name=\"devis\" type=\"radio\" value=\"Commande\" /><b>Commande </b></td></td> 
<td><form action=\"commande.php\" name='panier' method=\"post\" > 
<input name=\"achat\" type=\"hidden\" value=\"autorisation\"> 
<input name=\"panier\" type=\"submit\" value=\"Valider\"> 
</form></td> 
</tr> 
</table>"; 
?>

voici ma partie "commande"

while($var = each($caddie)) 
{ 
$sql1 = "SELECT * FROM produit WHERE IDProduit='$var[0]'"; 
$sql1 = mysql_query($sql1); 
$test = mysql_num_rows($sql1); 
while ($site=mysql_fetch_array($sql1)) 
{ 

$nombre = $_POST['qte']; 
$quantite = array ($nombre) ; 
$devis = $_SESSION["devis"]; 
foreach($quantite as $value) { 

echo"<table width=\"700px\" border=\"1\"><tr> 
<td align=\"left\" width=\"40%\">$site[LibelleProd]</td> 
<td align=\"left\" width=\"40%\">$site[RefProd]</td> 
<td align=\"center\">$value </td> 
</tr></table>"; 


D'avance merci
Modifié par Florent V. (20 Mar 2010 - 15:31)
merci je suis dessus ca fonctionne mais je post le tout dans la bdd le foreach qui fonctionner apres la page panier me mets un joli message d'erreur
Modifié par draak (20 Mar 2010 - 17:58)