Page 1 of 1
php code error, please help.
Posted: Sat Jan 17, 2009 4:50 pm
by tomsace
Hey, I wish to get multiple pages from one php file.
This is the code I have...
Code: Select all
<?php
$cmd = $_GET['cmd'];
if ($cmd=="") { $cmd = "page1.php"; }
@include('header.php');
switch($cmd)
{
case "page1":
@include('page1.php');
break;
case "page2":
@include('page2.php');
break;
case "page3":
@include('page3.php');
break;
}
@include('footer.php');
?>
In header .php it has 3 links. Linking to page1 page2 and page3. It all works fine except when the page loads it doesnt by default load page 1 which it what I want it to do. I thought the
Code: Select all
if ($cmd=="") { $cmd = "page1.php"; }
code was to load this page when loaded but it doesn't work!
Thanks alot.
Tom.
Re: php code error, please help.
Posted: Sat Jan 17, 2009 4:53 pm
by Burrito
Code: Select all
$cmd = isset($_GET['cmd']) ? $_GET['cmd'] : "");
Re: php code error, please help.
Posted: Sat Jan 17, 2009 5:11 pm
by tomsace
Thanks, but I cant seem to get this to work?
And ideas?
Re: php code error, please help.
Posted: Sat Jan 17, 2009 5:16 pm
by Burrito
I missed a paren:
Code: Select all
$cmd = (isset($_GET['cmd']) ? $_GET['cmd'] : "");
Re: php code error, please help.
Posted: Sat Jan 17, 2009 5:22 pm
by tomsace
Still doesn't come up!?
Should this replace the line:
Code: Select all
if ($cmd=="") { $cmd = "page1.php"; }
Sorry but im new to php.
Re: php code error, please help.
Posted: Sat Jan 17, 2009 5:30 pm
by Burrito
not it should replace this one:
Re: php code error, please help.
Posted: Sat Jan 17, 2009 5:36 pm
by tomsace
I have tried this but still no success??
Any more ideas?
Re: php code error, please help.
Posted: Sat Jan 17, 2009 5:39 pm
by Burrito
replace these two lines:
Code: Select all
$cmd = $_GET['cmd'];
if ($cmd=="") { $cmd = "page1.php"; }
with this:
Code: Select all
$cmd = (isset($_GET['cmd']) ? $_GET['cmd'] : "page1");
Re: php code error, please help.
Posted: Sat Jan 17, 2009 5:42 pm
by Burrito
at first I thought it was because you might be trying to set to a null reference.
but I've just reviewed you code more carefully and it's because you're setting $cmd = page1.php and your first case is looking for page1 (without the .php)
what I just posted above will work.
Re: php code error, please help.
Posted: Sat Jan 17, 2009 5:43 pm
by tomsace
Oh, Thanks alot. Works perfectly.
Thanks alot for all your help
