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.
Any help is very much appreciated. I wasn’t sure what info would be helpful but hers the answers so far:
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
Version of PHP in use
5.2.5 fresh install using Windows zip file direct from php.net
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.
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:
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.
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
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.
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!
Glad DT got it going… Still confused where your files located
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
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
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
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
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 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…