oyé!
voici mon problème :
je n'arrive pas à modifier les quantités d'article dans mon panier.
quand je veux modifier la quantité du 1er article, ça me donne le résultat du 2eme article
par exemple :
ref 1 ==> quantite 3 ==> prix Unit 79 ==> total du produit 237
ref2 ==> quantite 4 ==> prix Unit 99 ==> total du produit 396
et quand je modifie la quantite 3 de la ref 1 et que je met une quantite = 2 ça me donne : un total produit de 198 (ce qui est normalement egal à 2*99)
enfin bref c'est le boxon
voici tout le code :
désolée il est un peu long...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151 if(isset($_POST['sub_form'])) { //echo "Condition 1 vérifiée<br>"; if($_POST['sub_form']=="modifier") { //echo "Condition 2 vérifiée<br>"; $requete = "SELECT ref_produit FROM panier WHERE `id_cli` = '".$_SESSION['id_client']."'"; $quer = mysql_query($requete); // echo $requete."ref_produit<br>"; while ($fet = mysql_fetch_array($quer)) { $requete2 = "SELECT prix_produit FROM produit WHERE ref_produit = '".$fet['ref_produit']."'"; //echo $requete2."requete2<br>"; $quer2 = mysql_query($requete2); $fet2 = mysql_fetch_array($quer2); echo $fet2[0]."prix unitaire<br>"; echo $fet2[0]*$_POST['quantite']."prix<br>"; $sql = "UPDATE `panier` SET quantite = '".$_POST['quantite']."', total_produit = '".$fet2[0] * $_POST['quantite']."' WHERE ref_produit = '".$_POST['ref_produit']."'"; echo $sql."<br>"; $res = mysql_query($sql) or die (mysql_error()); $sql2 = "UPDATE `panier2` SET quantite = '".$_POST['quantite']."', total_produit = '".$fetch1[1] * $_POST['quantite']."' WHERE `id_cli` = '".$_SESSION['id_client']."' AND ref_produit = '".$_POST['ref_produit']."'"; //echo $sql2."<br>"; $res2 = mysql_query($sql2) or die (mysql_error()); } } elseif($_POST['sub_form']=="supprimer") { $sql = "DELETE FROM panier WHERE id_cli = '".$_SESSION['id_client']."' AND ref_produit = '".$_POST['ref_produit']."'"; $res = mysql_query($sql) or die (mysql_error()); $sql2 = "DELETE FROM panier2 WHERE id_cli = '".$_SESSION['id_client']."' AND ref_produit = '".$_POST['ref_produit']."'"; $res2 = mysql_query($sql2) or die (mysql_error()); } } $quant = "SELECT quantite FROM panier WHERE id_cli = '".$_SESSION['id_client']."' "; $querquant = mysql_query($quant); $fetchquant = mysql_fetch_array($querquant); if ($fetchquant[0] >0 ) { $total1 = "SELECT sum(total_produit) FROM panier WHERE id_cli = '".$_SESSION['id_client']."'"; // echo $total1."<br>"; $quertotal = mysql_query($total1); $fetchtotal = mysql_fetch_array($quertotal); // echo $fetchtotal[0]."<br>"; $total2 = "SELECT sum(total_produit) FROM panier2 WHERE id_cli = '".$_SESSION['id_client']."'"; //echo $total2."<br>"; $quertotal2 = mysql_query($total2); $fetchtotal2 = mysql_fetch_array($quertotal2); // echo $fetchtotal2[0]."<br>"; $sql = "SELECT ref_produit, quantite, total_produit FROM panier WHERE id_cli = '".$_SESSION['id_client']."' "; $res = mysql_query($sql) or die(mysql_error()); // formulaire echo"<center>"; echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>"; echo "<table border ='1' cellpadding='1' cellspacing='0' bordercolor='black'>"; echo "<tr>"; echo "<td><center><b>Réference</center></b></td>"; echo "<td><center><b>Désignation</center></b></td>"; echo "<td><center><b>Prix unitaire</center></b></td>"; echo "<td><center><b>Quantite</center></b></td>"; echo "<td><center><b>Total produit</center></b></td>"; echo "<td><center><b>Frais de port</center></b></td>"; echo "<td><center><b>Modif</center></b></td>"; echo "<td><center><img src = corbeille.GIF></center></td>"; echo "</tr>"; while($data = mysql_fetch_array($res)) { //echo $data['ref_produit']."Reference<br>"; $select = "SELECT designation_produit, prix_produit FROM produit WHERE ref_produit = '".$data['ref_produit']."' "; $quer = mysql_query($select); $fetch = mysql_fetch_assoc($quer); $frais = "SELECT frais_port FROM produit WHERE ref_produit = '".$data['ref_produit']."'"; $querfrais = mysql_query($frais); $fetchfrais = mysql_fetch_array($querfrais); echo "<tr>"; echo "<input type='hidden' name= 'ref_produit' value='".$data['ref_produit']."' />"; echo "<td>".$data['ref_produit']."</td>"; echo "<td>".$fetch['designation_produit']."</td>"; echo "<td>".$fetch['prix_produit']."</td>"; //echo "<td><input type=\"text\" size = 10 name=\"quantite\" value=\"".$fetchquantite[0]."\" /></td>"; echo "<td><input type='text' size = 10 name='quantite' value= '".$data['quantite']."' /></td>"; echo "<td>".$data['total_produit']."</td>"; echo "<td>".$fetchfrais['frais_port']."</td>"; echo "<td><input type='submit' name='sub_form' value='modifier' /></td>"; echo "<td><input type='submit' name='sub_form' value='supprimer' /></td>"; echo "</tr>"; echo "</form>"; } echo "</table>"; $tot = $fetchtotal[0] + $fetchfrais['frais_port']; echo "<tr><td><td></td><td></td><center><b>Total : ".$tot." </center></b></td></tr>"; $insert = "UPDATE panier SET total = '".$fetchtotal[0]."' WHERE id_cli = '".$_SESSION['id_client']."'"; $querinsert =mysql_query($insert); $insert = "UPDATE panier2 SET total = '".$fetchtotal2[0]."' WHERE id_cli = '".$_SESSION['id_client']."'"; $querinsert =mysql_query($insert); //$fetchinsert = mysql_fetch_array ($querinsert); echo "<form method = 'post' action = enregistrer.php> <input type = 'submit' name = 'enregistrer' value = 'enregistrer'> </form>"; echo "<form method = 'post' action = 'annulercommande.php'> <input type = 'submit' name = 'annuler' value = 'annuler la commande'> </form>"; } else { echo "<center><br><font size = +1>panier vide</font></center>"; } }
dans le cas présenté plus haut et avec des echo ça me donne :
79prix unitaire (echo $fet2[0]."prix unitaire<br>"
158prix (echo $fet2[0]*$_POST['quantite']."prix<br>";
UPDATE `panier` SET quantite = '2', total_produit = '158' WHERE ref_produit = '12'
99prix unitaire
198prix
UPDATE `panier` SET quantite = '2', total_produit = '198' WHERE ref_produit = '12'
vraiment merci si quelqu'un peut m'eclairer..
Partager