Jump to content


Photo

Switch help?


  • Please log in to reply
5 replies to this topic

#1 stridox

stridox
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 23 July 2006 - 09:21 PM

I know that this works

<?
	$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>
			<?
	};
?>

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?

#2 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 23 July 2006 - 09:26 PM

It's because of the set level of error reporting.

Use isset:
$Function =  isset($_POST['f'])? $_POST['f'] : $_GET['f'];


#3 stridox

stridox
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 23 July 2006 - 09:34 PM

Still comes up with the same thing; could I of installed it wrong?

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 23 July 2006 - 09:40 PM

I dont understand why your using the $_POST array at all.

$Function =  isset($_GET['f']) ? $_GET['f'] : '';


#5 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 23 July 2006 - 09:49 PM

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:
if(isset($_POST['f])) {
$func = $_POST['f];
elseif(isset($_GET['f'])) {
$func = $_GET['f];
else {
$func = '';
}



#6 stridox

stridox
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 24 July 2006 - 06:54 PM

thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users