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 8613143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:47:59+00:00 2026-06-12T04:47:59+00:00

I’m writing sales software that will be walking through a set of pages and

  • 0

I’m writing sales software that will be walking through a set of pages and on certain pages there are items listed to sell and when you click buy it basically just passes a hidden variable to the next page to be set as a session variable, and then when you get to the end it call gets reported to a database.

However my employer wanted me to include a shopping cart, and this shopping cart should display the item name, sku, and price of whatever you’re buying, as well as a remove button so the person doing the script doesn’t need to go back through the entire thing to remove one item.

At the moment I have the cart set to display everything, which was fairly simple. But I can’t figure out how to get the remove button to work. Here is the code for the shopping cart:

$total = 0;
//TEST CODE:
$_SESSION['itemname-addon'] = "Test addon";
$_SESSION ['price-addon'] = 10.00;
$_SESSION ['sku-addon'] = "1234h";

$_SESSION['itemname-addon1'] = "Test addon1";
$_SESSION ['price-addon1'] = 99.90;
$_SESSION ['sku-addon1'] = "1111";

$_SESSION['itemname-addon2'] = "Test addon2";
$_SESSION ['price-addon2'] = 19.10;
$_SESSION ['sku-addon2'] = "123";
//end test code
    
$items = Array
(
    "0"=> Array
    (
      "name" => $_SESSION['itemname-mo'],
      "price" => $_SESSION ['price-mo'],
      "sku" => $_SESSION ['sku-mo']
    ),
    "1" => Array
    (
      "name" => $_SESSION['itemname-addon'],
      "price" => $_SESSION ['price-addon'],
      "sku" => $_SESSION ['sku-addon']
    ),
    "2" => Array
    (
      "name" => $_SESSION['itemname-addon1'],
      "price" => $_SESSION ['price-addon1'],
      "sku" => $_SESSION ['sku-addon1']
    ),
    "3" => Array
    (
      "name" => $_SESSION['itemname-addon2'],
      "price" => $_SESSION ['price-addon2'],
      "sku" => $_SESSION ['sku-addon2']
    )
    
  );

$a_length = count($items);

for($x = 0; $x<$a_length; $x++){
$total +=$items[$x]['price']; 
}
$formattedtotal = number_format($total,2,'.','');
for($i = 0; $i < $a_length; $i++){
$name = $items[$i]['name'];
$price = $items[$i]['price'];
$sku = $items[$i]['sku'];
displaycart($name,$price,$sku);
}
echo "<br />
<b>Sub Total:</b> 
$$formattedtotal";
  
  function displaycart($name,$price,$sku){
    
    if($name != null || $price != null || $sku != null){
    
    if ($name == "no sale" || $price == "no sale" || $sku == "no sale"){
    echo ""; 
    }
    else{
      $formattedprice = number_format($price,2,'.','');
      echo "$name: $$formattedprice ($sku)";
      echo "<form action=\"\" method=\"post\">";
      echo "<button type=\"submit\" />Remove</button><br />";
      echo "</form>";
    }
    
    }
  }

So at this point I’m not sure where to go from here for the remove button.

  • 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-06-12T04:48:00+00:00Added an answer on June 12, 2026 at 4:48 am

    You can use arrays on session variables so you could change your format to

    $_SESSION[items][] = ("name"=>$name, "sku"=>$sku, "price"->$price)
    

    in your function displaycart() add the element

    echo "<input type='hidden' name='delete_sku' value='$sku'>\n";
    

    then when you delete you simply:

    $delete_sku = $_POST[delete_sku]; // the posted ID sent from delete form
    $i = 0;
    foreach ($_SESSION[items] as $item) {
        if ($item['sku'] == $delete_sku) {
            unset ($_SESSION[$i]);  // remove the item from the session array
        }
        $i++;
    }
    print_r ($_SESSION);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.