Really NooBish Question

Hi guys. I’ve been trying to figure out whst s gone wrong with my code for weeks now and short of giving up on php and moving to ssi/css your my last hope.

I’m trying to get a link to display on my main page but it won’t show for love nor money. I can get the news page to show but nothing else. Here’s the code:

<? $default_page="news"; if (!$id) { $id="news/news.php"; } else { $="$id"; } if (!@include("$id")) { include("404.html"); } ?>

The code for my link is:

<a href="?id=bakumatsu.html">Bakumatsu Kikansetsu Irohanihoheto</a>

My site:
yes it supports mysql and php

If anyone can offer some insight or even a better code that would be most helpful. An sorry for such a noobie question lol.

Thanx in advance,


Try adding this at the top of your PHP script:

$id = $_GET[‘id’];

I’m thinking register_globals is turned off (for GOOD reason, see the links in my signature), and your $id variable isn’t carried over automatically.

Also, this bit of code is NOT safe, you should ALWAYS check if the value of $id is valid (so not .htaccess or somethin like that).

Try file_exists() or in_array() (with an array of allowed pages of course).

Also have a look at your ELSE clause. You have

} else {

and I suspect it probably needs to be

} else {

In which case I question the usefulness of the else statement … basically what it does is assign the variable $id with the value in variable $id …

And what does $default_page do?

This should get you on your way:


<?php $id = $_GET['id']; if ($id != "" AND strstr($id, ".htm") > 0) { // this is, assuming your included // pages all end in .htm or .html if (file_exists($id)) { // does the requested file exist? include ($id); } else { include ("404.html"); } } else { include("news/news.php"); } ?>


Oops :oops:

I should really have looked at what I typed…

Obviously $id = “$id” is a stupid assignment. (Ugh what was I thinking).

Sorry about that.

None the less the point is that $="$id" is obviously wrong.

Zyppora you have a good solution (to what I think the problem is) there.

K so i tred the code and everything goes good until the second else statement
This is what dreamweaver tells me when i check the coding

Parse error: syntax error, unexpected T_ELSE in /www/ on line 91

Is there another way to write that ELSE statement, maybe create a new IF statement

Ah, I seem to have forgotten a bracket there fixed the code so it works now
Usually I don’t give solutions like that though, and if you really want to go on using PHP, you should be able to figure out the problem by yourself :) Learning how to read/decrypt the error/warning messages is a good start.

Thanks a billion for the help :) Everything is working good now.

Admin Edit: Please be careful of the duplicate posts. Subsequent duplicate posts were deleted.

Sponsor our Newsletter | Privacy Policy | Terms of Service