Page 1 of 1

Need some help here

Posted: Wed Jun 19, 2002 2:59 pm
by ibelimb
ok i have this code:

Code: Select all

<? 
if ($page == "") then &#123;
include "news.php"
&#125; else &#123;
include $page
&#125;
?>
and i get a parse error, how do i fix this, im calling the page like this: index.php?page=test.php

and i get the parse error, i also need some help fixing it up so that if the user calls a bad page, it displays a error (includes a file like error.php) and if no ?Page= was called it goes to news.php

Any help would be appreciated!

thanks,
Limb

Posted: Wed Jun 19, 2002 3:19 pm
by twigletmac
You forgot the semi-colons (;) at the end of the lines, try:

Code: Select all

<? 
if ($_GET&#1111;'page'] == '') then &#123; 
    include 'news.php';
&#125; else &#123; 
    include $_GET&#1111;'page']; 
&#125; 
?>
Mac

Posted: Wed Jun 19, 2002 3:19 pm
by kaizix

Code: Select all

<?

if ($page == "")
&#123;
   include ("news.php");
&#125;

else
&#123;
   include ("$page");
&#125;

?>
original code was missing ; and there's no then code is fixed above...also, if you're just starting to code...i would suggest getting into the habit of making the code more understandable when going through it...(as above)

also, to fix if a user has a bad page, you could put all the pages that someone would include into an array and see if it's in there...if not, go to error page. another way to do it if they have nothing is isset

Code: Select all

if(!isset($page))
&#123;
  include("news.php");
&#125;

Posted: Wed Jun 19, 2002 3:29 pm
by Eugene
try something like this:

Code: Select all

if ($_GET&#1111;'page'] == NULL)
&#123;
include "news.php";
&#125;
else
&#123;
if (!(include $_GET&#1111;'page'])) &#123;include "error.php";&#125;
&#125;
I think it could work, eventhough I am not sure about second if statement

Eug

Posted: Wed Jun 19, 2002 3:40 pm
by ibelimb
thnaks, im nto really new i was leanrign c++ so i was getting mixed with the two languages.