Jump to content

Switch help?


stridox

Recommended Posts

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 5

Notice: Undefined index: f in f:\site\switcher.php on line 5
Function A
Function B
Function C (Does not exist, use default)[/pre]

Any ideas?
Link to comment
https://forums.phpfreaks.com/topic/15424-switch-help/
Share on other sites

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]

Link to comment
https://forums.phpfreaks.com/topic/15424-switch-help/#findComment-62527
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.