Question

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

Notice: Undefined index: 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.

Was it helpful?

Solution

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.

OTHER TIPS

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>';
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top