Note that there are some explanatory texts on larger screens.

plurals
  1. PORemoving item using unset() from shopping cart creates mysql error
    text
    copied!<p>Hello everyone this is my first post on stack overflow.com I am trying to create shopping cart. Values are being stored in a session in two dimension table. First value represents item id in database, second - quantity of item.</p> <pre><code>foreach($cart_array as $row){ $sql = "SELECT * FROM prod_table WHERE id=".$row['0'].""; $cart_result = mysql_query($sql, $conn); while ($array = mysql_fetch_array($cart_result)) { echo "&lt;tr&gt;&lt;td&gt;". $array[manufacturer] . "&lt;/td&gt;"; echo "&lt;td&gt;". $array[model]."&lt;/td&gt;"; echo "&lt;td&gt;".$row['1']."&lt;/td&gt;"; $cart_value = $array[price]*$row['1']; //sum and store value of all products $total_cart_value += $cart_value; echo "&lt;td&gt;&amp;pound;" .$cart_value. "&lt;/td&gt;"; echo "&lt;td&gt;&lt;a href='search.php?kick_id=".$row['0']."'&gt;Remove&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;"; </code></pre> <p>OK, to remove item form cart user clicks remove and then he is being send back to the same page ( for some reason I had difficulty to use $_SERVER['PHP_SELF'} with GET method... ) and then different part of code is being triggered which is going to remove pair of values from $cart_array, using unset function.</p> <pre><code>if(isset($_GET['kick_id'])) { $t = count($cart_array); for( $u = 0; $u &lt; $t; $u++){ if ($cart_array[$u]['0'] == $_GET['kick_id']){ unset($cart_array[$u]['0']); unset($cart_array[$u]['1']); echo " Item has been removed from your cart"; $cart_array = array_values($cart_array); </code></pre> <p>And it actually removes pair of values but, now instead of running smoothly it displays error message : Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource ... I assume that there must be some "trace" of deleted values in session array which is causing error. How to fix code ? Is there any other method/approach to delete values ??</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