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
deathy
Forum Newbie
Posts: 7 Joined: Tue Jun 03, 2003 2:51 pm
Post
by deathy » Tue Nov 16, 2004 1:02 pm
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 » Tue Nov 16, 2004 1:38 pm
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 » Tue Nov 16, 2004 1:46 pm
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 » Tue Nov 16, 2004 2:33 pm
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;
?>