Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6727457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:03:06+00:00 2026-05-26T10:03:06+00:00

I am stuck on this code. I am making a web page and on

  • 0

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.

  <h1>Cart Contents?</h1>
    <div class="p2">
<?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 "<li><a href=\"category.php?cid=$fcid\">$fcat</a></li>\n";

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

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

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


} // End of while loop.

        ?>
        <h1>Specials?</h1>
        <div class="p2">
            <p>Maybe place specials or new items or related items here.</p>
        </div>

    </div>

    <div class="content">

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.
http://www.programmerskit.com/advPHP/ch5/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:03:06+00:00Added an answer on May 26, 2026 at 10:03 am

    Shouldn’t

            $itemCount=X;
            foreach($_SESSION['cart'] as X=>X){
    
                    for($i=0;$i<count(X);$i++){
                        $itemCount+=X;
                      }
    
                }
    

    just be:

    $itemCount = count($_SESSION['cart']);
    

    I can’t otherwise figure out what that code is supposed to be doing.

    Also, that code that outputs the cart appears to be in a while loop outputting each item category, so you will be displaying the cart multiple times, which I can only assume is not desired functionality.

    Also, another poster made a point about the invalid use of X as a constant, which is also a good point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm stuck at a point in making mutual friends code for my website. I
I am stuck now, here below is a snip from my paging code, this
I am doing one web application in grails.Now I am making signup page.In signup
There might be some very simple answer to this, but i am really stuck
Hello everyone I am completely stuck with this problem. I want add the name
I am stuck on this one. I am making a call to a service
I'm making a web-crawler. For finding the links in a page I was using
I have this code and I want to keep it elegant. I got stuck
I'm learning pointers, and gotten stuck for an hour now, with this code, #include
Why does this code not print an exception stack trace? public class Playground {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.