Really NooBish Question


#1

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:
http://sugoi-anime.110mb.com
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,

-Crim


#2

Try adding this at the top of your PHP script:

[php]
$id = $_GET[‘id’];
[/php]

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).


#3

Also have a look at your ELSE clause. You have

[php]
} else {
$="$id";
}
[/php]

and I suspect it probably needs to be

[php]
} else {
$id="$id";
}
[/php]


#4

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]

<?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"); } ?>

[/php]


#5

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.


#6

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/110mb.com/s/u/g/o/i/-/a/n/sugoi-anime/htdocs/index.php on line 91

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


#7

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.


#8

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.