Bonjour à tous,
Je suis actuellement sur un panier. Celui-ci fonctionne correctement mais dans des variables _POST ce qui n'est pas l'idéal pour la sécurité de mes tarifs. Mes données sont contenus dans une boucle FOREACH. Je souhaite que les résultats inscrire ces résultats dans une varaible de session dans un fichier nomme traitement.php et ensuite les afficher dans recapitulation.php.
Le but de la manoeuvre est de pouvoir revenir au panier et garder les produits, prix et quantités en mémoire.
Problème : Je ne sais pas comment m'y prendre et ne trouve pas d'info à ce sujet pour mon cas.
Mon panier :
Le FOREACH sur les prix de mon panier.php :
Le code de complet de mon panier.php :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 <select name="prix[<?= $product->id; ?>]"> <?php $formats = $DB->query("SELECT * FROM produits"); ?> <?php foreach ( $formats as $format ): ?> <option value="<?= $format->prix; ?>"><?= $format->format_name; ?></option> <?php endforeach ?> </select>
Ma page recapitulation.php :
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 <?php session_start(); if (!isset($_SESSION['login'])) { // $_SESSION['age'] = $data['age']; $album=$_SESSION['login']; header ('Location: album_connexion.php'); } ?> <?php require 'panier/header_panier.php'; ?> <div class="checkout"> <div class="title"> <div class="wrap"> <h2 class="first">Votre panier</h2> </div> </div> <div id="main"> <div id="facture"> <form method="post" action="recap.php" enctype="multipart/form-data"> <p class="entete"> <span class="col_0"></span> <span class="col_01">Nom</span> <span class="col_1">Format</span> <span class="col_2">Prix</span> <span class="col_3">Quantité</span> <span class="col_4">Prix total</span> <span class="col_5">Supprimer</span> </p> <?php $ids = array_keys($_SESSION['panier']); if(empty($ids)){ $products = array(); }else{ $products = $DB->query('SELECT * FROM images WHERE id IN ('.implode(',',$ids).')'); } foreach($products as $product): ?> <p class="ligne"> <span class="col_0"> <a href="#" class="img"> <img src="administration/images/<?= print $album; ?>/<?= $product->thumbnail_image; ?>" height="53"></a> </span> <span class="col_01 info-nom"><?= $product->normal_name; ?></span> <span class="col_1"> <select name="prix[<?= $product->id; ?>]"> <?php $formats = $DB->query("SELECT * FROM produits"); ?> <?php foreach ( $formats as $format ): ?> <option value="<?= $format->prix; ?>"><?= $format->format_name; ?></option> <?php endforeach ?> </select> </span> <span class="col_2 info-prix"></span> <span class="col_3"> <button type="button" class="btn_moins">-</button> <input type="text" name="quantite[<?= $product->id; ?>]"> <button type="button" class="btn_plus">+</button> </span> <span class="col_4 total-ligne"></span> <span class="col_5"> <a href="panier.php?delPanier=<?= $product->id; ?>" class="del"><img src="panier/img/del.png" title="Supprimer l'élément" alt ="supprimer l'élément"></a> </span> </p> <input type="hidden" value ="<?= $product->normal_name; ?>" name="normalname[<?= $product->id; ?>]"> <?php endforeach; ?> <p class="totaux"> <span></span> <span></span> <span></span> <span></span> <span> <input type="text" value ="<?php print $_SESSION['identifiantv'];?>" name="identifiantv" id="identifiantv"> <input type="text" id="idalbum" name="idalbum" value="<?php print $album;?>"> </span> <span class="text-right">Total HT :</span> <span id="totalht" class="text-right"></span> </p> <p class="totaux"> <span></span> <span></span> <span></span> <span></span> <span></span> <span class="text-right">Tva :</span> <span id="tva" class="text-right"></span> </p> <p class="totaux"> <span></span> <span></span> <span></span> <span></span> <span></span> <span class="text-right">Total TTC :</span> <span id="total" class="text-right"></span> </p> <input type="submit" value="continuer"> </form> </div> </div> </div> <div class="clear"></div> <?php require 'inc/footer.inc.php'; ?>
Ici je récupère bien mes resultats mais dans des variables _POST. J'aimerais pouvoir mettre ces resultats en SESSION.
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 <?php session_start(); if (!isset($_SESSION['login'])) { header ('Location: album_connexion.php'); } ?> <?php require 'panier/header_panier.php'; ?> <?php $album=$_SESSION['login']; ?> <p> <input type="text" value ="<?php print $_POST['identifiantv'];?>" name="identifiantv" id="identifiantv"> <input type="text" id="idalbum" name="idalbum" value="<?php print $_POST['idalbum'];?>"> </p> <p> <?php // on teste la déclaration de nos variables if (isset($_POST['quantite'], $_POST['normalname'], $_POST['prix'])) { foreach ($_POST['quantite'] as $key=>$values) { echo 'quantité :'.$_POST['quantite'][$key]; echo "</br>"; echo ' article :'. $_POST['normalname'][$key]; echo "</br>"; echo ' prix :'. $_POST['prix'][$key]; echo "</br></br>"; } } ?> </p> <p> <?php print_r($_POST); ?> ********************** </p> </div> <div class="clear"></div> <?php require 'inc/footer.inc.php'; ?>
Problème, je ne sais pas comment m'y prendre depuis une boucle FOREACH.
Quelqu'un aurait-il une solution a m'apporté ?
Cordialement,
Ruddy
Partager