Page 1 of 3
PHP Newbie Question
Posted: Sat Oct 05, 2002 5:24 pm
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) {
case "downloads":
include('downloads.php');
break;
default:
include('main.php');
break;}
?>
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.
Posted: Sat Oct 05, 2002 5:36 pm
by hob_goblin
try this:
Code: Select all
<?php
switch ($_GETї'goto']) {
case "downloads":
include('downloads.php');
break;
default:
include('main.php');
}
?>
1) read this
viewtopic.php?t=511
2) you don't need to put a break; in the default: switch
Posted: Sat Oct 05, 2002 6:01 pm
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.
Posted: Sun Oct 06, 2002 3:02 am
by Takuma
That's probably you got a old version of PHP try using $HTTP_GET_VARS instead of $_GET
Did you try this?
Posted: Sun Oct 06, 2002 9:13 am
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.
Posted: Sun Oct 06, 2002 10:52 am
by Takuma
Was it anything to do with register_globals? That seems to be causing a lot of troubles.
Posted: Sun Oct 06, 2002 1:19 pm
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
Posted: Sun Oct 06, 2002 2:14 pm
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
Posted: Tue Oct 08, 2002 9:46 am
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
or this to turn off error reporting
Posted: Wed Oct 09, 2002 3:56 am
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.
Posted: Sat Nov 23, 2002 10:59 pm
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!!
Posted: Sat Nov 23, 2002 11:03 pm
by hob_goblin
try something like this:
Code: Select all
if(isset($_GETї'downloads']){
if(!isset($_GETї'download_id']){
include 'downloads.php';
} else if($_GETї'download_id'] == "1"){
include 'games/1.php';
}
}
Posted: Sat Nov 23, 2002 11:10 pm
by Pocketx
Thanks! But if i were to imigrate it into the original code, how will it look like? Because i got some errors
Posted: Sat Nov 23, 2002 11:40 pm
by hob_goblin
Code: Select all
if($_GETї'page'] == "downloads"){
if(!isset($_GETї'download_id']){
include 'downloads.php';
} else if($_GETї'download_id'] == "1"){
include 'games/1.php';
}
} else {
include('main.php');
}
does that work? what are the errors?
Posted: Sat Nov 23, 2002 11:43 pm
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
<?php
switch ($_GETї'page']) {
case "downloads":
include('downloads.php');
break;
if($_GETї'page'] == "downloads"){
if(!isset($_GETї'download_id']){
include 'downloads.php';
} else if($_GETї'download_id'] == "1"){
include 'games/1.php';
}
} else {
include('main.php');
}
?>
I also did this
Code: Select all
<?php
if($_GETї'page'] == "downloads"){
if(!isset($_GETї'download_id']){
include 'downloads.php';
} else if($_GETї'download_id'] == "1"){
include 'games/1.php';
}
} else {
include('main.php');
}
?>
And I get this
Code: Select all
Parse error: parse error in /mnt/host-users/pocketx/test/index.php on line 3