Not understanding how to add cart into PHP
<p>I am stuck on this code. I am making a web page and on the side there is a place for a cart. And with the you should be able to click on an item and add it to cart. Well I am having trouble getting it to add it to cart. Can someone help me understand what I should be doing. I have been working on it for a few days and no matter what I am doing nothing is working. If i get the code to show you have 0 in your cart it wont add anything if i try to put it in the cart.</p>

<pre><code>  &lt;h1&gt;Cart Contents?&lt;/h1&gt;
    &lt;div class="p2"&gt;
&lt;?php
// Get all the categories and
// link them to category.php.

// Define and execute the query:
$q = 'SELECT category_id, category FROM categories ORDER BY category';
$r = mysqli_query($dbc, $q);

// Fetch the results:
while (list($fcid, $fcat) = mysqli_fetch_array($r, MYSQLI_NUM)) {

    // Print as a list item.
    echo "&lt;li&gt;&lt;a href=\"category.php?cid=$fcid\"&gt;$fcat&lt;/a&gt;&lt;/li&gt;\n";

    if($_SERVER['PHP_SELF']!="CART FILE"){
                echo "&lt;h1&gt;Cart Contents&lt;/h1&gt;";
                echo "&lt;div class=\"p2\"&gt;";
                $itemCount=X;
                foreach($_SESSION['cart'] as X=&gt;X){

                    for($i=0;$i&lt;count(X);$i++){
                        $itemCount+=X;
                      }

                }
                echo "&lt;a href=\"cart.php\"&gt;You have ".$itemCount." total items in your cart.&lt;/a&gt;";
                echo "&lt;/div&gt;\n";


} // End of while loop.

        ?&gt;
        &lt;h1&gt;Specials?&lt;/h1&gt;
        &lt;div class="p2"&gt;
            &lt;p&gt;Maybe place specials or new items or related items here.&lt;/p&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="content"&gt;
</code></pre>

<p>Ok here is a link to what the cart should do if you look over to the side it should do what that one is doing.
<a href="http://www.programmerskit.com/advPHP/ch5/" rel="nofollow">http://www.programmerskit.com/advPHP/ch5/</a></p>
