Jump to content


PHP Navigation Error


1 reply to this topic

#1 raenef

    Code Enforcer

  • Members
  • PipPipPip
  • 540 posts
  • Location:Battle Creek, Michigan
  • Interests:Web Development and Graphic Design

Posted 11 July 2005 - 07:35 PM

Okie so Im trying to setup a url like www.mydomain.com/index.php?id=gallery
and I have that working however if I dont include the ?id=gallery or ?id=anything and just do www.mydomain.com it returns the error
Notice: Undefined index: id in C:\server\www\kattest\index.php on line 2

I know this has been asked many times before in the forums, and I've searched and tried every possible way with similar results.
The Code I Am Using Now:
<?php
$id = $_GET['id'];
switch($id)
{
case "home":
include('assets/content/home.php');

break; case "page":
include('page.php');

break; case "page2":
include('otherpage.php');

break; case "contact":
include('contact.php');

default:
include('assets/content/home.php');
}
?>

Ive even tried this way
<?php
require('header.php');

$page = $_GET['page'];
if (($page == "home") or ($page =="")) {
include('news/news.php');
} else if($page == "projects") {
include('content/projects.html');
} require('footer.php');
?>
Edit: I of course edited this code to suit my need (I know it doesnt match the same navigation as the one before I just hurried to copy and paste)

With similar results saying undefined index page or something of the like.

Since these arent critical errors, I can probably fix them by turning off notices in my php installation (since they're both just notices) But I need to know how to do this (or a fix to the code)

Either way would work, thanks in advance. ;)


Edit: Fixed it, to turn off notices I just added error_reporting(0); to the beginning of the php script. :P

Edited by raenef, 11 July 2005 - 10:22 PM.


#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 12 July 2005 - 12:23 AM

well, fixed or not, your "switch" statement is technically incorrect. While it may work, you should think about updating it to this:
<?php
$id = $_GET['id'];
switch($id)
{
case "home":
include('assets/content/home.php');

break; case "page":
include('page.php');

break; case "page2":
include('otherpage.php');

break; case "contact":
include('contact.php');

break; default:
include('assets/content/home.php');
}
?>






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users