stridox Posted July 23, 2006 Share Posted July 23, 2006 I know that this works[code]<? $Function = ( $_POST['f'] ) ? $_POST['f'] : $_GET['f']; //Gets the function switch( $Function ) { case 'a': ?> <a href="switcher.php?f=b">Function B</a><br> <a href="switcher.php">No Function (Default used)</a> <? break; case 'b': ?> This is the function 'b'.<br> <a href="switcher.php?f=a">Function A</a><br> <a href="switcher.php">No Function (Default used)</a> <? break; default: ?> <a href="switcher.php?f=a">Function A</a><br> <a href="switcher.php?f=b">Function B</a><br> <a href="switcher.php?f=c">Function C (Does not exist, use default)</a> <? };?>[/code]But I just installed PHP on this machine, and I'm getting this:[pre]Notice: Undefined index: f in f:\site\switcher.php on line 5Notice: Undefined index: f in f:\site\switcher.php on line 5Function AFunction BFunction C (Does not exist, use default)[/pre]Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/15424-switch-help/ Share on other sites More sharing options...
448191 Posted July 23, 2006 Share Posted July 23, 2006 It's because of the set level of error reporting. Use isset:[code]$Function = isset($_POST['f'])? $_POST['f'] : $_GET['f']; [/code] Quote Link to comment https://forums.phpfreaks.com/topic/15424-switch-help/#findComment-62515 Share on other sites More sharing options...
stridox Posted July 23, 2006 Author Share Posted July 23, 2006 Still comes up with the same thing; could I of installed it wrong? Quote Link to comment https://forums.phpfreaks.com/topic/15424-switch-help/#findComment-62520 Share on other sites More sharing options...
trq Posted July 23, 2006 Share Posted July 23, 2006 I dont understand why your using the $_POST array at all.[code=php:0]$Function = isset($_GET['f']) ? $_GET['f'] : '';[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15424-switch-help/#findComment-62522 Share on other sites More sharing options...
448191 Posted July 23, 2006 Share Posted July 23, 2006 Okay, here's the deal: php can be set to leave or inlcude the reporting of notices, warnings en fatal errors. Likely, on the other machine it was set not to report notices. Mind you, this is NOT AN ERROR, it's a notice. It's triggered when you refer to var (or in this case index) not set.In your script you only refer to two vars and indexes: $_POST['f'] and $_GET['f'].Appearantly, in some state of your application, neither $_POST['f'] nor $_GET['f'] are set.Alternative:[code]if(isset($_POST['f])) {$func = $_POST['f];elseif(isset($_GET['f'])) {$func = $_GET['f];else {$func = '';}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15424-switch-help/#findComment-62527 Share on other sites More sharing options...
stridox Posted July 24, 2006 Author Share Posted July 24, 2006 thanks! Quote Link to comment https://forums.phpfreaks.com/topic/15424-switch-help/#findComment-63070 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.