开发者

PHP Notice: Undefined index

I am getting a Notice in a wordpress theme, but i think its a general PHP warning.

Notice: Undefined ind开发者_C百科ex: saved in ..\functions.php on line 255

The line 255 reads as:

if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';

Any suggestion, how i can fix it?

Thanks.


Change to:

if(isset($_REQUEST['saved']))

You should consider using a method specific super-array like $_GET or $_POST instead of the more general $_REQUEST array.


if ( isset($_REQUEST['saved']) && $_REQUEST['saved'] ) ...


Yes, this is a general php notice. You should use "empty" function like this:

<?php

if (!empty($_REQUEST['saved']))
    echo '<div id="message" class="updated fade"><p><strong>'
    . $themename
    . ' settings saved.</strong></p></div>';

This function will save you from "false", "0" and other "empty" values.


You can also check if a variable is set using isset(). Not sure if this applies to your specific situation.

if ( isset($_REQUEST['saved']) ) {
     echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜