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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:28:04+00:00 2026-05-23T17:28:04+00:00

I don’t understand why this code won’t only delete the pizza_id with the given

  • 0

I don’t understand why this code won’t only delete the pizza_id with the given key that is passed through the URL. I echo back the $_GET['key'] value to check if I have the desired number and it works fine.
The key value comes from another foreach $key=>$value loop that builds the shopping cart and has a delete link with the pizza id and the $key in it.

switch ($action) {
    case 'add':
        if ($cart) {
            $cart .= ','.$_GET['pizza_id'];
        } else {
            $cart = $_GET['pizza_id'];
        }
        break;
    case 'delete':
        echo "KEY: ".$_GET['key']."<br>";
        if ($cart) {
            $items = explode(',',$cart);
            $newcart = '';
            foreach ($items as $key => $item) 
            {
                if ($_GET['pizza_id'] != $item && $GET['key']!= $key ) 
                {
                    if ($newcart != '') 
                    {
                        $newcart .= ','.$item;
                    } 
                    else 
                    {
                        $newcart = $item;
                    }
                }
            }
            $cart = $newcart;
        }
        break;
}

EDIT: maybe I should also mention the basis of the code comes from this webpage http://v3.thewatchmakerproject.com/journal/276/

  • 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-23T17:28:04+00:00Added an answer on May 23, 2026 at 5:28 pm

    Well, at a minimum, you don’t need the $key in the foreach.

    if ($cart) {
        // you car is now an array of $items.
        $items = explode(',',$cart);
        $key = $_GET[ 'key' ];
        // are you sure pizza_id is correct too? You may want to echo/log it
        // if there is an $item which corresponds to $key, remove it.
        if( isset( $items[ $key ] ) )
              unset( $items[ $key ] );
    
        // this loop searches for all indexes of $_GET[ 'pizza_id' ] and removes them
        // comment this out if you don't want to do that. For some reason 
        // I missed it the first go round.
        while( ($pos = $array_search( $items, $_GET[ 'pizza_id' ] ) !== FALSE )
        {
            array_splice( $items, $pos, 1 );
        }
        // implode afterwards
        $cart = implode( ',', $items );
    }
    

    Another poster pointed out that your original code also has $GET['key']. Badness 10000. Do you have your warnings and error output set at the maximum level during development?

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

Sidebar

Related Questions

Don't think that I'm mad, I understand how php works! That being said. I
I don't understand where the extra bits are coming from in this article about
Don't understand, if Data.Map is and [] is. I found this out while wondering
Don't know if there is a better way to do this, so that is
Don't know the difference between the System.Window.Controls.TextBox and System.Windows.Forms.TextBox . Noticed that the System.Windows.Forms.TextBox
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know if this has been asked before, so point me to another question
Don't be frightened, its a very basic code. Just wanted to check with you
Don't overthink this - there's a very commonly used term and I ... have
Don't know if this is the right place to ask this, but I will

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.