注意:未定义的索引:在C:wampwww estsJoomlaWebsiteindex.php的


Notice: Undefined index: in C:wampwww estsJoomlaWebsiteindex.php on line 37

嘿,我得到了这个:注意:未定义的索引:在C:''wamp''www''tests''Joomla''Website''index.php的第37行

我的代码是:

<?php 
    $remarks=$_GET['remarks'];
    if ($remarks==null and $remarks=="")
    {
        echo '';
    }
    if ($remarks=='success')
    {
        echo 'Registration Success';
    }
?>

我不明白我为什么会得到这个。请帮忙!

首先,你没有说第37行在哪里…我不是巫师,但我可以从错误中猜出来。。。

由于错误为Undefined index,因此必须来自以下行:

$remarks=$_GET['remarks'];

在尝试获取其值之前,应该使用isset($_GET['remarks'])验证$_GET['remarks']是否为null。


其次,这条线没有任何意义,因为$remarks永远不可能是null"":

 if ($remarks==null and $remarks=="")


所以我会这样写代码:

<?php 
    $remarks = "";
    if ( isset($_GET['remarks']) ) {
        $remarks = $_GET['remarks'];
    }
    if ( $remarks == 'success' ) {
        echo 'Registration Success';
    }
?>