PHP Error

Hi, I am developing a site in PHP and keep getting this error. I am new to this having only used straight html before so it is likely to be something I have missed but canot see for looking . :sigh:Any help would be really appreciated.

I am using includes to create the navigation bar referenced by the line

<!-- AREA 02 - main navigation bar: START -->
			<div id="area02">
				
				<div id="navBar">
					
					<?php include("includes/mnNav.php") ?>
					
				</div>
				
			</div>	
			<!-- AREA 02 - main navigation bar: STOP -->

and the include code is:

<?php 

$pg = $_GET['pg']; 
								echo "<ul>";
									if ($pg == '' || $pg == 01) {
										echo "<li><a href='index.php?pg=01' class='navOn' title='Click here to return to the homepage'>HOME</a></li>";
									} else {
										echo "<li><a href='index.php?pg=01' title='Click here to return to the homepage'>HOME</a></li>";
									}
									if ($pg == 02) {
										echo "<li><a href='training.php?pg=02' class='navOn' title='Click here to see our current courses'>TRAINING</a></li>";
									} else {
										echo "<li><a href='training.php?pg=02' title='Click here to see our current courses'>TRAINING</a></li>";
									}
									if ($pg == 03) {
										echo "<li><a href='news.php?pg=03' class='navOn' title='Click here to read the latest industry news'>NEWS</a></li>";
									} else {
										echo "<li><a href='news.php?pg=03' title='Click here to read the latest industry news'>NEWS</a></li>";
									}
									if ($pg == 04) {
										echo "<li><a href='links.php?pg=04' class='navOn' title='Click here for some useful links'>LINKS</a></li>";
									} else {
										echo "<li><a href='links.php?pg=04' title='Click here for some useful links'>LINKS</a></li>";
									}
									if ($pg == 05) {
										echo "<li><a href='about.php?pg=05' class='navOn' title='Click here to learn a little about us'>ABOUT US</a></li>";
									} else {
										echo "<li><a href='about.php?pg=05' title='Click here to learn a little about us'>ABOUT US</a></li>";
									}
									if ($pg == 06) {
										echo "<li><a href='contact.php?pg=06' class='navOn' title='Click here for our contact details'>CONTACT US</a></li>";
									} else {
										echo "<li><a href='contact.php?pg=06' title='Click here for our contact details'>CONTACT US</a></li>";
									}
								echo "</ul>";							
?>

Everything on the page loads but I get the following error where the nav. bar should be -

Notice: Undefined index: pg in C:\PL08\includes\mnNav.php on line 3

What makes this more frustrating is that this problem occurs when I view it through localhost but if I upload the files to my host’s server it works fine.

TIA

change the

$pg = $_GET[‘pg’];

to

if($_GET['pg]){$pg = $_GET[‘pg’]};

DT.

Thanks for the help DT :slight_smile:

I have tried this, and unfortunately the error has changed to:

Parse error: syntax error, unexpected ‘}’ in C:\PL08\includes\mnNav.php on line 3

Where’s that smiley with the guy throwing his pc out of the window?

have you any suggestions how I can clear this one?

Thanks

Not sure if I can help but a few question to help piece together the jigsaw…

  1. Is …C:\PL08\includes\mnNav.php the location of the actual file ?
  2. Version of PHP in use
  3. What are you using to develop and display your PHP on your local machine.

I think… its the

href='index.php?pg=01

bit :confused:

Because your include in the 1st section is a local host file

the knock on effect is that the referencing in the include file is literally looking for a file called… index.php?pg=01 on your system.

Hi PMM

Any help is very much appreciated. I wasn’t sure what info would be helpful but hers the answers so far:

  1. Is …C:\PL08\includes\mnNav.php the location of the actual file ?

Yup, I’m editing the files on a machine here then ftp’ing them to a paid host server. All the files are in a folder C:\PL08

  1. Version of PHP in use

5.2.5 fresh install using Windows zip file direct from php.net

  1. What are you using to develop and display your PHP on your local machine.

I’m using MS Expression Web Ver2 set up to preview files via Expression Development Server + localhost + php (more info here http://www.ew-resource.co.uk/php.aspx

This is all on a Vista 32 machine

If you need any more details more details please ask.

Thanks for your help

What is really sending me in circles here is that if I upload it to my isp’s servers it all works fine using the original format I just cannot get it to load locally :crash:

Cheers

Is the PHP compiler in the same local folder?

Not direct related to php but when i’ve had that sort of problem its been the other way round due to unix being picky about capital letters and windows not giving a stuff. not being into this area but paths to files would be my guess.

Thanks everyone :slight_smile:

Droid, I slide my PHP noob hat on and say I don’t think it is but I’m using a number of includes on this page and they all display correctly and work apart from this one.

Peige - you could well be onto somthing here and I suspect it is somthing small that just need a setting or reference changed. I just can’t see it though

Cheers

I think trial and error to start…

Make you code in the 1st bit to include some error checking…

ie.

<?php include("includes/mnNav.php") ?>

Change to…

<?php
if ((include "includes/mnNav.php") == 'OK') {
echo 'OK';
}

See if its executing the include.

ok, you are all missing the point, and I’m guilty of a typo.

If the $_GET variable of pg is not there, it will barf with the original error message you posted, because it doesn’t exist so you cannot assign it to a variable.

@PMM, it is definately doing the include, the error is as described above.

My code I posted should be


if( isset($_GET['pg'])) { $pg = $_GET['pg']; }else{$pg ='';}

I would also suggest that rather than all those IF statements in your include file, you use a switch block instead.

DT.

Thanks again everyone,

DT, Your new code still returns the same error although it now also adds this to it!

The odd thing is that before it would stop the page loading in it’s tracks and all I got was the background and the error message, now it displays the page entirely but has this above error code ‘overlaid’ in grey.

Notice: Undefined index: pg in C:\MSTSS\Sites 2007\PL08\includes\mnNav.php on line 3


Notice: Undefined variable: pg in C:\MSTSS\Sites 2007\PL08\includes\mnNav.php on line 6
HOME

Notice: Undefined variable: pg in C:\MSTSS\Sites 2007\PL08\includes\mnNav.php on line 11
TRAINING

Notice: Undefined variable: pg in C:\MSTSS\Sites 2007\PL08\includes\mnNav.php on line 16
NEWS

Notice: Undefined variable: pg in C:\MSTSS\Sites 2007\PL08\includes\mnNav.php on line 21
LINKS

Notice: Undefined variable: pg in C:\MSTSS\Sites 2007\PL08\includes\mnNav.php on line 26
ABOUT US

Notice: Undefined variable: pg in C:\MSTSS\Sites 2007\PL08\includes\mnNav.php on line 31
CONTACT US

The other slightly more frustrating part is that uploaded to the isp servers the page displays perfectly with either version.

Beginning to wonder if I should go back to old fashioned html and notepad! :frowning:

DT - knew that but wanted him to follow a process :wink: because I was going to add some code :wink:

<?php set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] ); ?>

Try putting that at the beginning of the 1st document - want to rule out or in something
while trying to get PHP installed on my main rig.

Laptop is down battery capput so working blind here… main rig is being temermental to my attempt to get my fav enviroment running.

post edited

less haste more speed

DT.

:trophy:

DT’s last edit made it work.

Thank you all very much for your help.

Cheers

Glad DT got it going… Still confused where your files located :confused:

Was that latter post running off the server or off the dev machine ?

its changed from C:\PL8 to C:\MSTSS\Sites 2007\PL08\ somewhere along the line.

Still think it was setup if it worked on the Webserver and not the local otherwise orginal code going by DT’s observations should have resulted in the orginal code keeling over on the web machine too :confused:

Can’t test my thought as main machine truly refuses to run just giving me a “Error 267: creating process” grrr Time for a start from scratch and re-install windows :frowning:

ok, the difference in the localhost returning the error and the hosting not will be down to the setup of php installation. PHP has a number of different options for how strictly it behaves with errors, or whether a variable must be declared before it is used.

Finding two hosts with the same php config is very rare, if you want to look then upload a page with


<?php
  phpinfo();
?>

DT.

Hi PMM

I have yet to work out exactly how/why it works now but for the moment I am very relieved it does. Sorry for the confusion over file location, all my posts referred to files held on my local machine which have in reality the 'C:\MSTSS\Sites 2007\PL08 structure. I shortend it in the posts simply to try and avoid unnecessary text adding to the confusion.

Given that all the other parts were working fine I didn’t think it would make a difference. Pleaes don’t tell me taht doing this has been the cause of this

Cheers

It OK

PHP can be somewhat bizarre at time’s and a simple syntax change can cause PHP to treat a statement differently.

File location and its structure being one of them… deferences between Actual location and a HTTP location… I.e. difference between the APPs right to link a file into its pre-processing verse an actual page you would visit.

That was my line of thinking… Obviously wrong :wink: but again something controlled by the PHP setup like the error reporting.

In a sense DT has shown the proper way to deal with the Variable statement… in essence ‘pg’ had no value when the linked file kicks in…