Note that there are some explanatory texts on larger screens.

plurals
  1. PORemoving item from cart - php
    primarykey
    data
    text
    <p>I am trying to remove an item from the basket using a 'delete' link. Currently, when the link is clicked, it isnt doing anything. If possible, could somebody steer me in the right direction please. I have a loop of each item in the order where $item will be the current item and $key is the index of the array.</p> <p>I then use html to output the items. Within this section I have a delete link:</p> <pre><code>&lt;td&gt;&lt;a href="processorder.php?delete=&lt;?=$key?&gt;"&gt;Delete&lt;/a&gt;&lt;/td&gt; </code></pre> <p>I also have the process of this:</p> <pre><code>if (isset($_GET['delete']) &amp;&amp; $_GET['delete']) { $key = $_GET['delete']; unset($_SESSION['order'][$key]); } </code></pre> <p>Below is all of the code for reference:</p> <pre><code>&lt;?php // start the session handler require_once('dbfunction.php'); //connect to database $conn = DB(); require_once('header.php'); if (isset($_GET['delete']) &amp;&amp; $_GET['delete']) { $key = $_GET['delete']; unset($_SESSION['order'][$key]); } //first of all, get this items information $query = "SELECT * FROM ".$tablename." WHERE ".$key." = '".$item['prod_id']."'"; $sql = mysql_query($query, $conn); $product = mysql_fetch_assoc($sql); //html for this product $grand_total = isset($grand_total) ? $grand_total : 0; $line_cost = $product['price'] * $item['quantity']; $grand_total += $line_cost; ?&gt; &lt;tr&gt; &lt;td&gt;&lt;?=$product['common_name'];?&gt;&lt;/td&gt; &lt;td&gt;&lt;?=$item['prod_type'];?&gt;&lt;/td&gt; &lt;td&gt;&lt;?=$product['price'];?&gt;&lt;/td&gt; &lt;td&gt;&lt;input type='text' name='quantity[]' value='&lt;?=$item['quantity'];?&gt;' size='2' /&gt;&lt;/td&gt; &lt;td&gt;&amp;pound;&lt;?=number_format($line_cost, 2);?&gt;&lt;/td&gt; &lt;td&gt;&lt;a href="processorder.php?delete=&lt;?=$key?&gt;"&gt;Delete&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    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