PHP Newbie Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Tom
Forum Newbie
Posts: 20
Joined: Sat Oct 05, 2002 5:24 pm
Location: Southwest FL

PHP Newbie Question

Post by Tom »

Alright.
I'm trying to make my index.php page to where I can make links look like "index.php?goto=links".

In the index.php file I have this:

Code: Select all

<?php
switch ($goto) &#123;
case "downloads":
include('downloads.php');
break;
default:
include('main.php');
break;&#125;
?>
Now here's where my problem is. I've checked my code at least 10 times and I can't seem to figure out why I keep getting this:

"Warning: Undefined variable: goto in c:\my documents\site\flballer\new\index.php on line 2"

When i used to have a small website and I played around with php, I never got anything like this while doing the "index.php?page=blah" code.

Pleaaaasee Help!

Take it Easy, - Tom.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

try this:

Code: Select all

<?php 
switch ($_GET&#1111;'goto']) &#123; 
case "downloads": 
include('downloads.php'); 
break; 
default: 
include('main.php'); 
&#125; 
?>
1) read this viewtopic.php?t=511
2) you don't need to put a break; in the default: switch
Tom
Forum Newbie
Posts: 20
Joined: Sat Oct 05, 2002 5:24 pm
Location: Southwest FL

Post by Tom »

Thanks, but it doesn't work. It's still trying to tell me this:

"Warning: Undefined variable: _GET in c:\my documents\site\index.php on line 2"

Take it easy, - Tom.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

That's probably you got a old version of PHP try using $HTTP_GET_VARS instead of $_GET
Did you try this?
Last edited by Takuma on Sun Oct 06, 2002 1:37 pm, edited 1 time in total.
Tom
Forum Newbie
Posts: 20
Joined: Sat Oct 05, 2002 5:24 pm
Location: Southwest FL

Post by Tom »

I erased everything that had to do with php on my computer (besides php files i had written, of course) and made sure i followed the directions correctly. I still don't know what was wrong, but it seems to work fine now :). Thanks guys!

Take it easy, - Tom.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Was it anything to do with register_globals? That seems to be causing a lot of troubles.
Tom
Forum Newbie
Posts: 20
Joined: Sat Oct 05, 2002 5:24 pm
Location: Southwest FL

Post by Tom »

It's got nothing to do with Register_Globals. I'm using 4.0.6 because I have 56k and never decided to wait the 40 minutes or so to download the newest versions every 3 weeks or so.. :?

Take it easy, - Tom
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Hopefully you'll find the lastest version worth the wait. You shouldn't need to upgrade again until they finally release 4.3.

Mac
Oxy
Forum Newbie
Posts: 17
Joined: Fri Apr 19, 2002 5:47 am
Location: U.K
Contact:

Post by Oxy »

Your using PHP with higher than normal error reporting settings, which means you need to define each variable before you use it or turn down your error setting.

Put this at the top of your script

Code: Select all

$goto = 0;
or this to turn off error reporting

Code: Select all

error_reporting(0);
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

you shouldnt need to do either of those suggestions, you should have your own error handling that will trap the event and prevent the error from being displayed. If you set the variable at the top of the page you are just going to overwrite any variable passed to the script if GLOBALS are turned on, and just cause problems later on when trying to determine the value of $goto.
User avatar
Pocketx
Forum Commoner
Posts: 37
Joined: Fri Aug 23, 2002 9:54 pm

Post by Pocketx »

Hmm.. when i try

<?php
switch ($_GET['page']) {
case "downloads":
include('downloads.php');
break;
case "downloads&download_id=1":
include('games/1.php');
break;
default:
include('main.php');
}
?>

When i try with the & on the browser, it doesnt work, it only gose to the page downloads.. Help please!!
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

try something like this:

Code: Select all

if(isset($_GET&#1111;'downloads'])&#123;
 if(!isset($_GET&#1111;'download_id'])&#123;
 include 'downloads.php';
 &#125; else if($_GET&#1111;'download_id'] == "1")&#123;
 include 'games/1.php';
 &#125; 
&#125;
User avatar
Pocketx
Forum Commoner
Posts: 37
Joined: Fri Aug 23, 2002 9:54 pm

Post by Pocketx »

Thanks! But if i were to imigrate it into the original code, how will it look like? Because i got some errors
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Code: Select all

if($_GET&#1111;'page'] == "downloads")&#123; 
if(!isset($_GET&#1111;'download_id'])&#123; 
include 'downloads.php'; 
&#125; else if($_GET&#1111;'download_id'] == "1")&#123; 
include 'games/1.php'; 
&#125; 
&#125; else &#123;
include('main.php');
&#125;
does that work? what are the errors?
User avatar
Pocketx
Forum Commoner
Posts: 37
Joined: Fri Aug 23, 2002 9:54 pm

Post by Pocketx »

Code: Select all

Parse error: parse error in /mnt/host-users/pocketx/test/index.php on line 7
My code:

Code: Select all

&lt;?php
switch ($_GET&#1111;'page']) { 
case "downloads": 
include('downloads.php'); 
break;
if($_GET&#1111;'page'] == "downloads"){ 
if(!isset($_GET&#1111;'download_id']){ 
include 'downloads.php'; 
} else if($_GET&#1111;'download_id'] == "1"){ 
include 'games/1.php'; 
} 
} else { 
include('main.php'); 
}
?&gt;
I also did this

Code: Select all

&lt;?php
if($_GET&#1111;'page'] == "downloads"){  
if(!isset($_GET&#1111;'download_id']){  
include 'downloads.php';  
} else if($_GET&#1111;'download_id'] == "1"){  
include 'games/1.php';  
}  
} else {  
include('main.php');  
} 
?&gt;
And I get this

Code: Select all

Parse error: parse error in /mnt/host-users/pocketx/test/index.php on line 3
Post Reply