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

  • Home
  • SEARCH
  • 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 7937185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:27:31+00:00 2026-06-03T22:27:31+00:00

Hi I have a shopping cart but my problem is when I delete multiple

  • 0

Hi I have a shopping cart but my problem is when I delete multiple Item it wont process but if I delete only one item on check box it work well here is my code below I want to figure out if what is wrong on my code:

 $cart = $_SESSION['items'];

if(isset($_POST['del'])) {

  if ($cart) {
  $newcart = array();
  foreach ($cart as $item) {

    foreach ($_POST['itemid'] as $del) {
        $delete = $del;
    }

    if ($del != $item) {

          if ($newcart != '') {
            $newcart[] = $item;
          } else {
            $newcart[] = $item;
          }

    }   


  }
  $cart = $newcart; 
  }

}

$_SESSION['items'] = $cart;

Here is my form:

<form action="cart.php" method="post">
<table>
<tr>
<td><input type="checkbox" name="itemid[]" value="1"></td><td>Item 1</td><td>5</td>
</tr>
<tr>
<td><input type="checkbox" name="itemid[]" value="2"></td><td>Item 2</td><td>5</td>
</tr>
<tr>
<td><input type="checkbox" name="itemid[]" value="3"></td><td>Item 3</td><td>5</td>
</tr>
<tr>
<td><input type="checkbox" name="itemid[]" value="4"></td><td>Item 4</td><td>5</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="del" value="Delete"></td>
</tr>
</table>
</form>

If I check multiple Item and submit the delete button, the item was not delete but if I only check one the item deleted.

Thank you for you help very much appreciated.

  • 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-03T22:27:32+00:00Added an answer on June 3, 2026 at 10:27 pm

    You have name=”items” in the code, but you’re looking for $_POST[‘itemid’] – those should be the same as each other? Looks like you’re getting confused with the sessions value.


    Post your edit:

    foreach ($_POST['itemid'] as $del) { 
        $delete = $del; 
    } 
    

    will leave only the LAST items as $delete. you could try

    foreach ($cart as $item) { 
    
        if (!in_array($item, $_POST['itemid'])) { 
    
            if ($newcart != '') { 
                $newcart[] = $item; 
            } else { 
                $newcart[] = $item; 
            } 
    
        }    
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found a slight problem within Magento, to do with the shopping cart.
I have a calculator if you will. It's a shopping cart, but upon change
I'm making a shopping cart. In one tab, I have a table view controller
Okay, so I have a shopping cart problem. I've decided to roll out my
I am looking to implement something that appears to have shopping cart functionality, but
I'm developing a lightweight shopping cart but have become stumped with products that have
I have a stripped down shopping cart application, currently with one model cart, the
I am stuck with one of my shopping cart, Here is my problem A,
I have setup a shopping cart price rule of 10%. If I add a
I'm writing a simple shopping cart application and have hit a road block. Currently

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.