I’ve been working on a project on my local server. The time has come to upload it so I did just that. I started to test it out online and my navigation isn’t working.
The navigation works by doing this:
<a href="index.php?p=add">Add</a>
The page then checks whether $p exists and if it does, it shows the relevant content. For some reason though my content isn’t showing up when I click the links. I turned on error reporting, and I added this (line 39)
echo $p;
to the document. Now I get this error: Notice: Undefined variable: p in /home/silver/public_html/admin/index.php on line 39 but only when testing online and it works fine when I test it locally.
I can post my code if I need to, but there’s a lot of it and I’m not sure which bit is the problem.
UPDATE:
Thanks for all the replies, but I’m confused as to how you use your suggestions as I’m used to doing things the way I was.
At the moment, I do this to check what the $p variable is
<?php if(!isset($p)) { // DEFAULT PAGE VIEWED AT INDEX.PHP ?>
And use this to link to the page:
<a href="index.php?p=add">Add New Item</a>
You’re relying upon
register_globals, an outdated and deprecated feature of PHP. This feature automatically translates GET, POST, COOKIE, SERVER etc. variables and inserts them into the global scope. This means thatfile.php?p=blahwould result in$p == 'blah'. This is a bad idea for lots of different scoping and security reasons outlined in the PHP manual.Use the superglobals (e.g.
$_GET,$_POST,$_SERVER) instead.In response to your updated question, your code
should become