Hello guys,

I was a beginner going thru some books I came across a part called the Command System (though they stated that there is no offical name for it) but this is what they mean by that "A central Processing PHP file that can be used to Reference other .php code funtion stored in different php script file for their functionalities to be executed when they are required".

here was an example. below is two differnt file

main.php

<?php
include ("welcome.php");
include ("page1.php");

switch($cmd)
{
case Page1:
showPage1();
break;

default:
   showWelcome();
 break;

}
?>

welcome.php
<?php
function showWelcome()
{
?>

   <html>
  <head><title>Welcome</title></head>

<body>
<center>This is Welcome page You are WELCOME</center>
<br><br>
You can also visit page 1.

<br>
<ul>
<li><a href="main.php?cmd=page1">Page 1</a></li>
</ul>

</body>
</html>
<?php
}
?>

page1.php

<?php
function showPage1()
{
?>
<center>
You are welcome to page 2 but You can also visit the main page
<br><br>
<ul>
<li><a href = "main.php?cmd=main">Main Page</a></li>
</ul
</center>

<?php
}
?>

so when I execute this code it only display the default switch statement and when ever i click on the page 1 link it only change the address in the address bar of the browser and nothing happens.

please help.

Am just a biginner if their is any probs in my code I will be gratefull to be corrected.

Thanks

Hakeem.

    Welcome to the forums, Hakeem.

    You may want to edit your post and use the

     bbcode tags[/url] around your code samples, which will make them much easier to read.

      Use $_GET['cmd'] instead of $cmd. The latter is only available if the [man]register_globals[/man] option is turned on, and that option is now deprecated and should not be depended upon. (Any book that assumes it will be available is either out-of-date or not very good.)

        thanks friend i appreciate the reply, am sorry that in my post i didn't stated the version of PHP am using. the version was 4. and please if am to still turn on the global variable I will be glad if you guys can typed out the steps for me.

        Thanks

        Hakeem.

          Do not turn on register_globals -- it is several years out-of-date and a very bad habit to get into. Instead, change the way you reference variables from external sources to use the appropriate "super-global" arrays: $GET, $POST, $COOKIE, or $SESSION, etc. So in your example, instead of...

          switch($cmd)

          ...you would use...

          switch($_GET['cmd'])

          See http://www.php.net/manual/en/language.variables.external.php for more info about these variables.

          PS: your case statement's value needs to be quoted when it's a string literal:

          case "Page1":
          

            thanks for the reply am on coding. I will get in touch when am thru.

              I appreciate your concern.
              thanks again I'll get in touch if their is anything.

              regard
              hakeem

                Write a Reply...