Page 1 of 1

Notice: Undefined index

Posted: Tue Nov 16, 2004 1:02 pm
by deathy
i keep getting the following error

Notice: Undefined index: act in D:\web\wwwroot\plat\index.php on line 32

Code: Select all

$page = array(
'idx' => 'news',
'join' => 'join'
);

$_REQUESTї'act'] = $_REQUESTї'act'] == '' ? "idx" : $_REQUESTї'act'];

if (!isset($pageї $_REQUESTї'act'] ]) )
{
$_REQUESTї'act'] = 'idx';
}

require $root.'/sources/'.$pageї $_REQUESTї'act'] ].'.'.EXT;
that is the code for it.

how can i resolve this without turning of error reporting

Posted: Tue Nov 16, 2004 1:38 pm
by timvw
use [php_man]isset[/php_man] to find out if the variable exists

Posted: Tue Nov 16, 2004 1:46 pm
by deathy
yes it is.

1. because the page changes
2. because i did isset :/

Posted: Tue Nov 16, 2004 2:33 pm
by rehfeld
you didnt do isset, at least in the code you posted

you did an isset on the page array, you need to do it on the $_REQUEST

Code: Select all

<?php

$_REQUEST['act'] = (empty($_REQUEST['act'])) ? "idx" : $_REQUEST['act']; 

?>
but generally its not a good idea to change superglobals, i would do something like this

Code: Select all

<?php

$page = array(
'idx' => 'news',
'join' => 'join'
);

$action = 'idx'; // default

if (!empty($_REQUEST['act'])) {
    if (isSet($page[$_REQUEST['act']])) {
        $action = $page[$_REQUEST['act']];
    }
}

require $root.'/sources/'.$action.'.'.EXT;

?>