-1

I am trying to pass a variable from one page to another using a URL but I get a NOTICE. I have read that NOTICE or WARNINGS can be suppressed, by I want to learn how to fix this if possible. Thanks!

Notice: Undefined index: status in /view_dept.php on line 139

this is the URL and where the query happens - (technically the page1 - where the variable comes from):

header('location:view_dept.php?status=success');

This is the "page2", where I need to pass the variable so I can echo a success message. This is the MAIN PAGE.

<?php
    if( $_GET['status'] == 'success'):
        echo 'SUCCESS';
    endif;
?>
April G
  • 111
  • 1
  • 13

1 Answers1

3

To avoid the Notice, try isset() to check if the index status is present

<?php
if( isset($_GET['status']) && $_GET['status'] == 'success'):
    echo 'SUCCESS';
endif;
?>
RJ Anoop
  • 763
  • 13
  • 26