Erreur de variable lors de l'envoi du form
Salut. :D
Je suis en train de me faire un site de e-commerce à la main et j'en suis au panier.
Voici le code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| <table>
<tr>
<th style="color : red;"> * </th>
<th style="text-align : center;" colspan=2> Article </th>
<th style="text-align : center;"> Description </th>
<th> Prix unitaire </th>
<th> Quantité </th>
<th> Total </th>
</tr>
<?php
while($resultat_panier = mysql_fetch_array($execution_contenu_panier))
{
?>
<form method="post" name="panier" action="suppression_article_panier.php">
<tr>
<td style="text-align : center">
<a href="javascript:document.forms['panier'].submit()" style="font-weight : bold; color : red;">X</a>
</td>
<td>
<a href="enluminures/max/<?php echo $resultat_panier['image']; ?>" title="<?php echo $resultat_panier['titre']; ?>" rel="lightbox">
<img src="enluminures/min/<?php echo $resultat_panier['image']; ?>" />
</a>
</td>
<td style="font-weight : bold;">
<?php echo $resultat_panier['titre']; ?>
</td>
<td style="font-style : italic;"> <?php echo $resultat_panier['description']; ?> </td>
<td style="color : red; text-align : right;"> <?php echo $resultat_panier['prix']; ?> € </td>
<td style="color : blue; text-align : center;"> <?php echo $resultat_panier['quantite']; ?> </td>
<td style="font-weight : bold; color : red; text-align : right;"> <?php $total_prix_article = $resultat_panier['quantite'] * $resultat_panier['prix']; echo $total_prix_article; ?> €</td>
<input type="hidden" name="id_article" value="<?php echo $resultat_panier['id']; ?>" />
<?php
$total_commande = $total_commande + $total_prix_article;
?>
</tr>
</form>
<?php
}
?>
</table> |
Pour l'exemple, j'ai plusieurs articles dans le panier et je veux en supprimer un.
J'ai donc un lien en JavaScript qui envoie le formulaire, et le script dans le "action" réceptionne la variable ID de l'article pour le supprimer.
Ça marchait très bien en PHP, mais comme un gros bouton gris par ligne n'était pas esthétique, j'ai changé pour le lien JS.
Seulement, quand je veux supprimer n'importe quelle ligne, il supprime toujours le dernier article ajouté. La variable ID envoyée est toujours la dernière entrée.
Est-ce que vous auriez une idée pour faire en sorte que l'envoie du form envoie la bonne variable ?
En espérant avoir été assez clair. :aie:
Merci ! ;)