Note that there are some explanatory texts on larger screens.

plurals
  1. POShoppingcart gives same product PHP
    text
    copied!<p>Afternoon,</p> <p>I am having some difficulties with my <strong>shoppingcart</strong> for a <strong>webshop</strong>. In my cartArr (array that has the id's of my products got from my database) there are the right id's of my products that i bought. I also have a shoppingcart on my productspage that has the counts the right amount of items in my cartArr (so far so good).</p> <p>When i want to show my products he only shows the last product i've clicked * times i've bought something. Logical because he doesn't remember it in my session array.</p> <p>I know what my problem is but i can't figure out how to fix it. </p> <pre><code>/*Shoppingcart.php*/ &lt;?php $id = ''; if(isset($_POST['shoppingCart']['btnSubmit'])) { $id = $_POST['shoppingCart']['id']; $productDAO = new ProductDAO(); $result = $productDAO-&gt;getProductById($id); if( in_array($id,$_SESSION['cartArr'])) { array_push($_SESSION['cartArr'], $id); echo '&lt;pre&gt;'; print_r('Hallo'); echo '&lt;/pre&gt;'; } } $smarty -&gt; assign('arrProducts',$result); $smarty -&gt; assign('id',$id); $smarty -&gt; assign('cartArr',$_SESSION['cartArr']); $smarty -&gt; assign('product',$result) /*Shoppingcart.tpl*/ {foreach $cartArr as $item} &lt;div class="winkelkarItem"&gt; &lt;img src="{$arrProducts.image}" class="winkelkarImgPosition" alt="chimay" title="chimay"/&gt; &lt;ul class="winkelkarBeschrijving"&gt; &lt;li&gt;{$arrProducts.naam}&lt;/li&gt; &lt;li&gt;{$arrProducts.prijs}&amp;euro;&lt;/li&gt; &lt;li&gt;&lt;input class="winkelkarAmmount" type="text" value="2"/&gt;&lt;/li&gt; &lt;li&gt;7.08&amp;euro;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; {/foreach} /*SQL statement to get my products out of my database in a seperate file ProductDAO*/ public function getProductById($id) { try { $sql = 'SELECT * FROM tblProduct WHERE id = :id'; $stmt = $this-&gt;dbh-&gt;prepare($sql); $stmt-&gt;bindValue(':id',$id); $stmt-&gt;execute(); $result = $stmt-&gt;fetch(); } catch(PDOException $e) { echo $e-&gt;getMessage(); } return $result; } ?&gt; </code></pre> <p>Thx in advance for all help. </p> <p>Short: Arrproducts has to get into my session Trough a foreach i need to make my items @ shoppingcart.tpl The id of the products i've clicked is in cartArr.</p> <p>Thx!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload