If Isset and Equals

Hi all, I keep getting a notice saying that I have an undefined index: action. How can I fix this? I guess I need to incorporate isset into the code but can’t make it work?

if($_GET['main_page']=="basket" && $_GET['action']=="remove"):
    $bag->update_item($_GET['prod'], 0);
    $_SESSION['cart'] = serialize($bag);
    header('Location: /basket/');
endif;
if (isset($_GET['main_page']) && $_GET['main_page'] == "basket" && isset($_GET['action']) && $_GET['action'] == "remove"):

Hey dude, that’s perfect, massive help. Didn’t know why I didn’t think of that myself :confused:

Just a tip/reminder: order matters.

Short-circuit evaluation - Wikipedia, the free encyclopedia

Another “tip”, sometimes it’s easier to evaluate if you break it down a little.


<?php
$isBasketRequest  = 'basket' === filter_input(INPUT_GET, 'main_page');
$isProductRemoval = 'remove' === filter_input(INPUT_GET, 'action');

if($isBasketRequest && $isProductRemoval){
  #do stuff
}

:slight_smile:

Hey Anthony, massive help, simplifies things greatly. Thanks again :slight_smile: