Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding items to a cart not working, can't see any errors
    primarykey
    data
    text
    <p>I'm currently designing a shopping cart following a tutorial online.</p> <p>I have followed as much as I can down to each detail, with some changes such as variable names etc changing.</p> <p>I have checked through the code below, however when I clicked "Add To Cart" it doesn't display the added item in the side bar.</p> <p>Any suggestions as to what the issue may be? (The code is only the segment relating to the sidebar, the products php is in a separate php file.)</p> <pre><code>&lt;div id="sidebar"&gt; &lt;h1&gt;Cart&lt;/h1&gt; &lt;?php if(isset($_SESSION['cart'])){ $sql = "SELECT * FROM products WHERE SKU IN("; foreach($_SESSION['cart'] as $id =&gt; $value){ $sql .= $id. ","; } $sql = substr($sql,0,-1) . ") ORDER BY SKU ASC"; $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)){ ?&gt; &lt;p&gt;&lt;?php echo $row['name']; ?&gt;&lt;?php echo $_SESSION['cart'][$row['SKU']]['quantity']; ?&gt;&lt;/p&gt; &lt;a href="index.php?page=cart"&gt;Go To Cart&lt;/a&gt; &lt;?php } }else { echo "&lt;p&gt;Your part is empty. &lt;br /&gt;Please add some products&lt;/p&gt;"; } ?&gt; &lt;/div&gt; </code></pre> <p>Section of code from products PHP file which does the adding:</p> <pre><code>&lt;?php if(isset($_GET['action']) &amp;&amp; $_GET['action'] == "add"){ $id = $_GET['id']; if(isset($_SESSION['cart'][$id])){ $_SESSION['cart'][$id]['quantity']++; } else { $sql2 = "SELECT * FROM products WHERE SKU=$id"; $query2 = mysql_query($sql2); if(mysql_num_rows($query2) != 0){ $row2 = mysql_fetch_array($qery2); $_SESSION['cart'][$row2['SKU']] = array("quantity" =&gt; 1, "price" =&gt; $row2['price']); } else { $message = "This product ID is invalid"; } } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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