Bonjour, je suis entrain d'essayé de créé un panier depuis ma base de donnée, les données sont récupéré mais n'arrive pas a s'affiché sur la page panier et l'erreur qu'il m'affiche c'est : Warning: array_keys() expects parameter 1 to be array, string given in D:\Site\panierPHP\panier.php on line 27. pour moi il récupère l'id 0,1,2,3 etc... non!? et quand je fait un $search_array il me la trouve
voici le code
et voici les classe panier
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 <?php require 'header.php'; ?> <div class="checkout"> <div class="title"> <div class="wrap"> <h2 class="first">Shopping Cart</h2> </div> </div> <form method="post" action="panier.php"> <div class="table"> <div class="wrap"> <div class="rowtitle"> <span class="name">Product name</span> <span class="price">Price</span> <span class="quantity">Quantity</span> <span class="subtotal">Prix avec TVA</span> <span class="action">Actions</span> </div> <?php $search_array = array('premier' => 1, 'second' => 4); if (array_key_exists('premier', $search_array)) { echo "L'élément 'premier' existe dans le tableau"; } $ids = array_keys($_SESSION['panier']); if(empty($ids)){ $products = array(); }else{ $products = $DB->query('SELECT * FROM accesoires WHERE id IN ('.implode(',',$ids).')'); } foreach($products as $product): ?> <div class="row"> <a href="#" class="img"> <img src="img/<?= $product->id; ?>.jpg" height="53"></a> <span class="name"><?= $product->Articles; ?></span> <span class="price"><?= number_format($product->Prix_site,2,',',' '); ?> </span> <span class="quantity"><input type="text" name="panier[quantity][<?= $product->id; ?>]" value="<?= $_SESSION['panier'][$product->id]; ?>"></span> <span class="subtotal"><?= number_format($product->Prix_site * 1.196,2,',',' '); ?> </span> <span class="action"> <a href="panier.php?delPanier=<?= $product->id; ?>" class="del"><img src="img/del.png"></a> </span> </div> <?php endforeach; ?> <div class="rowtotal"> Grand Total : <span class="total"><?= number_format($panier->total() * 1.196,2,',',' '); ?> </span> </div> <input type="submit" value="Recalculer"> </div> </div> </form> </div> <?php require 'footer.php'; ?>
si quelqu'un pourait m'expliquer mes erreurs
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 <?php class panier{ private $DB; public function __construct($DB){ if(!isset($_SESSION)){ session_start(); } if(!isset($_SESSION['panier'])){ $_SESSION['panier'] = array(); } $this->DB = $DB; if(isset($_GET['delPanier'])){ $this->del($_GET['delPanier']); } if(isset($_POST['panier']['quantity'])){ $this->recalc(); } } public function recalc(){ foreach($_SESSION['panier'] as $product_id => $quantity){ if(isset($_POST['panier']['quantity'][$product_id])){ $_SESSION['panier'][$product_id] = $_POST['panier']['quantity'][$product_id]; } } } public function count(){ return array_sum($_SESSION['panier']); } public function total(){ $total = 0; $ids = array_keys($_SESSION['panier']); if(empty($ids)){ $products = array(); }else{ $products = $this->DB->query('SELECT id, Prix_site FROM accesoires WHERE id IN ('.implode(',',$ids).')'); } foreach( $products as $product ) { $total += $product->Prix_site * $_SESSION['panier'][$product->id]; } return $total; } public function add($product_id){ if(isset($_SESSION['panier'][$product_id])){ $_SESSION['panier'][$product_id]++; }else{ $_SESSION['panier'][$product_id] = 1; } } public function del($product_id){ unset($_SESSION['panier'][$product_id]); } }
merci,
Partager