bonjour,
j ai passer des valeurs par session a la place de get et cela augmente tout de meme la qte du panier quand je rafraichit la page comment eviter cela?
je penser que par session cela marcherai.
merci de votre aide.
Version imprimable
bonjour,
j ai passer des valeurs par session a la place de get et cela augmente tout de meme la qte du panier quand je rafraichit la page comment eviter cela?
je penser que par session cela marcherai.
merci de votre aide.
Peux tu donner un bout de code ?
1 page:
panier.phpCode:
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 <?php session_start(); //session_destroy(); include("../include/session.php"); $id=$_GET['id']; $l=$_GET['l']; $q=$_GET['q']; $p=$_GET['p']; $_SESSION['id'] = $id ; $_SESSION['l'] = $l ; $_SESSION['q'] = $q ; $_SESSION['p'] = $p ; $body=' <div id="choix"> <div id="conteneur_panier" style="float:left;"> <h4>Choix 1</h4> <ul> <br /><li><a href="../index.php">Continuer mes achats</a><br /><br /></li> </ul> </div> <div id="conteneur_panier"style="float:right;margin-bottom:100px;" > <h4>Choix 2</h4> <ul class="last_element"> <br /><li><a href="panier.php?action=ajout">Commander maintenant</a><br /><br /></li> </ul> </div> </div> '; //$body.='<a href="choix.php?action=ajout&id='.$pro['produit_id'].'&l='.$sous_categorie['categorie_titre'].'&q=1&p='.$pro['produit_prix'].'"><img src="../images/caddie.gif">Commande terminer</a>'; include("../include/base.php"); ?>
fonctions-panier.phpCode:
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 <?php include("../include/session.php"); include_once("fonctions-panier.php"); session_start(); $ida=$_SESSION['id']; $la=$_SESSION['l']; $qa=$_SESSION['q']; $pa=$_SESSION['p']; if (isset($_GET['action'])) { $erreur=false; if(in_array( $_GET['action'],array('ajout', 'suppression'))) $action = $_GET['action']; else $erreur=true; $id = intval($ida); $l = preg_replace('#\v#', '', $la); $q = intval($qa); $p = floatval($pa); } elseif(isset($_POST['action'])) { unset($_GET); $erreur=false; if(in_array($_POST['action'],array('ajout', 'suppression'))) $action=$_POST['action']; else $erreur=true; $id = floatval($_POST['id']); $l = preg_replace('#\v#', '',$_POST['l']); $p = floatval($_POST['p']); $QteArticle = array(); $i=0; foreach ($_POST['QteArticle'] as $contenu){ $QteArticle[$i++] = intval($contenu); } } if ($erreur==false){ switch($action){ Case "ajout": ajouterArticle($id,$l,$q,$p); break; Case "suppression": supprimerArticle($id); break; /*Case "refresh" : for ($i = 0 ; $i < count($QteArticle) ; $i++) { modifierQTeArticle($_SESSION['panier']['libelleProduit'][$i],round($QteArticle[$i])); } break;*/ Default: break; } } $body='<form method="post" action="panier.php"> <div id="panier"> <table> <tr> <td colspan="4"><h3>Votre panier<h3></td > </tr> <tr class="libelle"> <td>Libellé</td> <td>Quantité</td> <td>Prix Unitaire</td> <td>Action</td> </tr> '; if (creationPanier()) { //$nbArticles=count($_SESSION['panier']['libelleProduit']); $nbArticles=count($_SESSION['panier']['idProduit']); echo $_SESSION['panier']['idProduit']; //session_destroy(); if ($nbArticles <= 0) $body.='<tr><td>Votre panier est vide. </ td></tr>'; else { for ($i=0 ;$i < $nbArticles ; $i++) { $body.='<tr>'; $body.='<td>'.htmlspecialchars($_SESSION['panier']['libelleProduit'][$i]).'</ td>'; $body.='<td>'.htmlspecialchars($_SESSION['panier']['qteProduit'][$i]).'</td>'; $body.='<td>'.htmlspecialchars($_SESSION['panier']['prixProduit'][$i]).'</td>'; $body.='<td><a href="'.htmlspecialchars("panier.php?action=suppression&id=".rawurlencode($_SESSION['panier']['idProduit'][$i])).'">Supprimer</a></td>'; $body.='</tr>'; } $body.='<tr><td colspan=\"4\">'; $body.='<h3>Montant Total de votre commande: '.MontantGlobal(); $body.=' euros</h3></td></tr>'; } } $body.='</table></div> </form> </body> </html>'; include("../include/base.php"); ?>
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
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 <?php function creationpanier(){ $ret=false; if (isset( $_SESSION['panier'])) $ret = true; else { $_SESSION['panier']=array(); $_SESSION['panier']['idProduit'] = array(); $_SESSION['panier']['libelleProduit'] = array(); $_SESSION['panier']['qteProduit'] = array(); $_SESSION['panier']['prixProduit'] = array(); $ret=true; //print_r($_SESSION); //session_destroy(); } return $ret; } function ajouterArticle($idProduit,$libelleProduit,$qteProduit,$prixProduit){ if (creationpanier()) { $positionProduit = array_search($idProduit,$_SESSION['panier']['idProduit']); if ($positionProduit !== false) { $_SESSION['panier']['qteProduit'][$positionProduit] += $qteProduit ; } else { array_push( $_SESSION['panier']['idProduit'],$idProduit); array_push( $_SESSION['panier']['libelleProduit'],$libelleProduit); array_push( $_SESSION['panier']['qteProduit'],$qteProduit); array_push( $_SESSION['panier']['prixProduit'],$prixProduit); } } else echo "Un problème est survenu veuillez contacter l'administrateur du site."; } function supprimerArticle($idProduit){ if (creationpanier()) { $tmp=array(); $tmp['idProduit'] = array(); $tmp['libelleProduit'] = array(); $tmp['qteProduit'] = array(); $tmp['prixProduit'] = array(); for($i = 0; $i < count($_SESSION['panier']['idProduit']); $i++) { if ($_SESSION['panier']['idProduit'][$i] !== $idProduit) { array_push( $tmp['idProduit'],$_SESSION['panier']['idProduit'][$i]); array_push( $tmp['libelleProduit'],$_SESSION['panier']['libelleProduit'][$i]); array_push( $tmp['qteProduit'],$_SESSION['panier']['qteProduit'][$i]); array_push( $tmp['prixProduit'],$_SESSION['panier']['prixProduit'][$i]); } } $_SESSION['panier'] = $tmp; unset($tmp); } else echo "Un problème est survenu veuillez contacter l'administrateur du site."; } function modifierQTeArticle($idProduit,$qteProduit){ if (creationpanier()) { if ($qteProduit > 0) { $positionProduit = array_search($idProduit, $_SESSION['panier']['idProduit']); if ($positionProduit !== false) { $_SESSION['panier']['qteProduit'][$positionProduit] = $qteProduit ; } } else supprimerArticle($idProduit); } else echo "Un problème est survenu veuillez contacter l'administrateur du site."; } function MontantGlobal(){ $total=0; for($i = 0; $i < count($_SESSION['panier']['idProduit']); $i++) { $total += $_SESSION['panier']['qteProduit'][$i] * $_SESSION['panier']['prixProduit'][$i]; } return $total; } ?>
pour éviter ça, il faut que tu fasses 2 pages : la 1re page fait l'action de modifier la quantité et après l'action tu fais une redirection vers la 2e page
bonjour,
je ne suis pas trop pourrais tu m indiquer comment faire avec mon code actuel.
merci