Ok here is my coding. The design_start and design_end functions just output HTML designs. When I load this I get the following error:
Notice: Undefined variable: go in C:...\try.php on line 7
news (default)

<?php
include("libs/design.php");
include("libs/modules.php");

design_start();

switch ($go)   //<--------line 7
{
	case 'news':
	print "news";
	break;

case 'solutions':
print "products/solutions";
break;

case 'contact':
print "contact";
break;

case 'clients':
print "clients";
break;

case 'about':
print "about us";
break;

case 'support':
print "service/support";
break;

default:
            print "news (default)";
break;
}
design_end();
?>

The problem is I am trying to pass a variable through the web address such as try.php?go=news would display "News" etc....

I have done many websites before with this structure and this has never happened before... can anyone help me?

Also, note, this is the first time I put PHP on a Windows 2000 Server... maybe the problem stems from that?

    There's two things going on here...

    $go is always undefined because register_globals is off. Read the [man]register_globals[/man] manual page for details.

    You're getting an "undefined variable" notice because you have error reporting cranked up (probably error_reporting(E_ALL)). This is a good thing, though it can take some getting used to. There is a difference between a blank string ("") and the undefined value (null), but PHP usually lets you pretend they are the same. With "notice" level error reporting PHP is letting you know that it's faking it. This can be helpful, because if you typo a variable name, it'll warn you that you're using an undefined variable instead of pretending your typing is fine. Use [man]isset[/man] or [man]empty[/man] to check if a variable is set without triggering those notices.

    Consider using a function like this, to work around both issues:

    function getvar($varname, $default = '') {
        if (isset($_REQUEST[$varname])) return $_REQUEST[$varname];
        else return $default;
    }
    

    Then use switch(getvar('go')) instead of switch($go).

      So how would I go about passing the $go variable through the URL with globals turned off? I understand how I can read it...

      For instance the URL would read:
      index.php?go=news

      Let me know please!!

        You pass it like you would with register_globals on. You just read it with the $_GET superglobal instead.

          replace $go with $_GET['go'] in the switch..

            Write a Reply...