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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.