当我将一个变量传递到另一个页面时,我会收到一个通知:未定义的索引


I get a Notice: Undefined index when I pass a variable to another page

我试图使用URL将变量从一个页面传递到另一个页面,但收到了一个通知。我已经读到通知或警告可以被抑制,如果可能的话,我想学习如何解决这个问题。谢谢

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

这是URL和查询发生的位置-(从技术上讲是page1-变量的来源):

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

这是"page2",我需要在其中传递变量,这样我就可以回显成功消息。这是主页。

<?php
    if( $_GET['status'] == 'success'):
        echo 'SUCCESS';
    endif;
?>

为了避免通知,请尝试isset()检查索引状态是否存在

<?php
if( isset($_GET['status']) && $_GET['status'] == 'success'):
    echo 'SUCCESS';
endif;
?>