Need some help here

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

Post Reply
ibelimb
Forum Newbie
Posts: 18
Joined: Wed Jun 19, 2002 2:59 pm
Location: New York, USA

Need some help here

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Last edited by twigletmac on Wed Jun 19, 2002 3:20 pm, edited 1 time in total.
kaizix
Forum Commoner
Posts: 50
Joined: Tue Jun 18, 2002 9:16 pm
Location: california
Contact:

Post 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;
User avatar
Eugene
Forum Newbie
Posts: 24
Joined: Tue Jun 18, 2002 12:40 pm
Location: Montreal

Post 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
ibelimb
Forum Newbie
Posts: 18
Joined: Wed Jun 19, 2002 2:59 pm
Location: New York, USA

Post by ibelimb »

thnaks, im nto really new i was leanrign c++ so i was getting mixed with the two languages.
Post Reply