Fix PHP Notice: 'Undefined index' on Wordpress

tlt2w

I'm trying to fix the Undefined index PHP notice on a wordpress site.

At the moment this is what I got:

    <?php if($_SESSION['currency-select'] == "a") echo 'selected="selected"';?>

I tried to write this way but then the site goes down:

    <?php if(isset($_SESSION['currency-select'] == "a")) echo 'selected="selected"';?>

Also, I have a query which is also without isset and i'm trying to fix it:

                    if($_SESSION['currency-select'] == 'b') {

                if($_GET['pricing'] == '1') {

                    $args['meta_query'][] = array(

                        'key' => 'price',

                        'value' => array( '0', '250' ),

                        'compare' => 'BETWEEN',

                        'type' => 'numeric'

                    );

                }

I tried to write:

      if(isset($_GET['pricing'] == '1')) {
      if($_GET['pricing']) {

but it doesn't work as well.

Thanks for your support!

stUrb

Try looking if the variable isset and then check the contents of it.

if( isset($_GET['pricing']) && $_GET['pricing'] == '1' ){
   //- do some magic
}

With your if-clause you check if the clause itself isset() instead of the variable.

ps: why do you check the number 1 as a string 1?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related