Notice: Undefined index

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
deathy
Forum Newbie
Posts: 7
Joined: Tue Jun 03, 2003 2:51 pm

Notice: Undefined index

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

use [php_man]isset[/php_man] to find out if the variable exists
deathy
Forum Newbie
Posts: 7
Joined: Tue Jun 03, 2003 2:51 pm

Post by deathy »

yes it is.

1. because the page changes
2. because i did isset :/
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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;

?>
Post Reply