Hi Guys,

Need some help here scratching head....

<?
switch ($_GET['page']) {
case 'about':
      $inc('about.php');
      break;
case 'home':
      $inc('home.php');
      break;
case 'contact':
      $inc('contact.php');
      break;
case 'gtr':
      $inc('gtr.php');
      break;
case null:
      $inc('home.php');
      break;
default:
      $inc('404.php');
      break;
}
?>

I get the following error;

Notice: Undefined index: page in C:\Work\rb26net\site ideas\includes\functions.inc on line 2

i dont understand why? Can anybody help me?
Is it because I haven't stated what 'page' is? i wouldn't have thought so as its not a variable.. ?? 🙁

Thanks,

Christian

    thanks Tuf, but i get the undefined index when i am just loading the index - the rest of the page loads, but this error just sits there..

    how do i define it?

    Thanks,

    Christian

      if your switch statement is meant to be a function (in function.inc) then shouldnt u set it as a function, because otherwise it will try to work whenever function.inc is included in ANY page

      <? 
      function get_page($page) {
      
      if ($page == '') { $page='home'; }
      switch ($page){ 
      case 'about': 
            $inc('about.php'); 
            break; 
      case 'home': 
            $inc('home.php'); 
            break; 
      case 'contact': 
            $inc('contact.php'); 
            break; 
      case 'gtr': 
            $inc('gtr.php'); 
            break; 
      case null: 
            $inc('home.php'); 
            break; 
      default: 
            $inc('404.php'); 
            break; 
      } 
      }
      ?> 
      

      then call it using

      get_page($_GET['page']);

      where u need it

        Ahhh great thanks!!

        but, i dont understand this -

        get_page($_GET['page']); 
        

        how do i call it using that? do i use that as a link and substitue 'page' for whatever the page is?

        Thanks again,

        Christian

          get_page(); // Calls the function

          $_GET['page'] // is the variable needed by that function to work properly

          the variables are defined outside of the function by you or the script in this case it is decided by the url used to access the page

          eg

          http://www.yoursite.com/index.php?page=about

          would set $_GET['page'] to 'about'

          and then using that the switch function would run and return your include

            ok great - thanks very much, i'll have a play and see if i can get it to work.

            I appreciate your help!

            Christian

              bugger it... i'm still getting

              Notice: Undefined index: page in C:\Work\rb26net\site ideas\index2.php on line 15

              ....

              my index2.php page is thus;

              <?
              ini_set('include_path', 'includes/');
              include ("header.php");
              include ("functions.inc");
              ?>
                          <table width="600" height="300" border="0">
                              <tr>
                                  <td width="85" align="left" valign="top">
                                  <?
                                  include ("menu.php");
                                  ?>
                                  </td>
                                  <td align="left"><div id="scrollcell">
              <?php
              get_page($_GET['page']);
              
              ?>
              
                              </div></td>
                          </tr>
                      </table>
                  </td>
              </tr>
              </table>
              </body>
              </html>
              

              and my functions.inc is thus;

              <?
              function get_page($page) {
              
              if ($page == '') { $page='home'; }
              switch ($page){
              case 'about':
                    include('about.php');
                    break;
              case 'home':
                    include('home.php');
                    break;
              case 'contact':
                    include('contact.php');
                    break;
              case 'gtr':
                    include('gtr.php');
                    break;
              case null:
                    include('home.php');
                    break;
              default:
                    include('404.php');
                    break;
              }
              }
              ?>
              

              can you shed any light?

              the links seem to work now, but it just displays this error a lot..

              Thanks again,

              Christian

                erm try using

                <?php
                get_page($HTTP_GET_VARS['page']);

                ?>

                instead of

                <?php
                get_page($_GET['page']);

                ?>

                  Actually, you only need to check if $_GET['page'] has been set, e.g.

                  <?php
                  if (isset($_GET['page'])) {
                  	switch ($_GET['page']) {
                  	case 'about':
                  	      $inc('about.php');
                  	      break;
                  	case 'home':
                  	      $inc('home.php');
                  	      break;
                  	case 'contact':
                  	      $inc('contact.php');
                  	      break;
                  	case 'gtr':
                  	      $inc('gtr.php');
                  	      break;
                  	case null:
                  	      $inc('home.php');
                  	      break;
                  	default:
                  	      $inc('404.php');
                  	      break;
                  	}
                  }
                  else {
                  	$inc('404.php');
                  }
                  ?>

                    hey guys - thanks for all the help.

                    When I uploaded it to my server i didn't get the error anymore, so it must be an issue with PHP on my local machine...

                    GRRR.. i coulda had this working long ago. 🙂

                    Thanks again!!

                    Christian

                      Write a Reply...