Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two possible solutions - </p> <ol> <li><p>Check if the value of session was <code>"0"</code> (even though "0" is false, <code>$v = "0"; isset($v)</code> will return true).</p></li> <li><p>destroy the session if <code>$_POST</code> was <code>"0"</code>.</p></li> </ol> <h2>change your index.php to -</h2> <pre><code>&lt;?php session_start(); require_once 'carwash.php'; if (isset($_SESSION['encoded_cartopass']) &amp;&amp; $_SESSION['encoded_cartopass']) { // first let's get the variable from the session $encoded_cartopass = $_SESSION['encoded_cartopass']; // now let's unpack it $cartopass = unserialize($encoded_cartopass); // echo quantity echo "Your shopping cart contains {$cartopass-&gt;getQuantity()} items. &lt;br /&gt;&lt;br /&gt;"; } else { echo "Your shopping cart contains 0 items. &lt;br /&gt;&lt;br /&gt;"; } ?&gt; </code></pre> <h2>or change your process.php to -</h2> <pre><code>&lt;?php require_once 'carwash.php'; if (isset($_POST['submit']) &amp;&amp; $_POST['quantity']) { if (!isset($_SESSION['encoded_cartopass'])) { // construct and set quantity $cartopass = new carwash(); $cartopass-&gt;setQuantity($_POST['quantity']); // construct and encode session session_register('encoded_cartopass'); $_SESSION['encoded_cartopass'] = serialize($cartopass); } else { // if session is existing, decode it and // increment quantity $encoded_cartopass = $_SESSION['encoded_cartopass']; $cartopass = unserialize($encoded_cartopass); $cartopass-&gt;incrementQuantity($_POST['quantity']); // encode class and assign to session and // session is used pass to index.php $_SESSION['encode_cartopass'] = serialize($cartopass); } } else { unset($_SESSION['cartopass']); session_destroy(); } echo "&lt;script&gt;window.location.href='index.php'&lt;/script&gt;"; ?&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.
    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