Ezilon.com - Target Your Audience, be Seen in Your Region

PHP POST var to include

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.

He has: 52 posts

Joined: Apr 2006

Hi again.

I am making my own layout, as I was suggested to before, and it's going great. I'm learing more than I could ever have done before, and the pride of doing it by myself is tremendous. *I'm a big boy now!*

Okay, but like every time I post here, I have a problem. I'm using a little script to pull a text file out of a lower directory, based on the post variables I get. Unfortunately, it's really not working.

Here's my code:

<?php
$article
= $_POST['articles'];
if (
$article == "\" ) {
    echo \"The article you were looking for was not found.\";
} else {
    echo \"The if statement evaluated to false\";
    include(\"/articles/\".$article\".txt\");
}
?>

I'm getting this error:

Quote: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in c:\appserv\www\abyss\pages\viewarticle.php on line 9

'Line 9' refers to my 'include' line.

Can you tell me why this isn't working? Also, can you find me a solution to my crafty users who plays with the POST variables and hits a wrong/invalid article (to a text file that doesn't exist)?

Thanks.

~Max

Webmaster! Smiling

timjpriebe's picture
DeveloperModeratorSponsor

He has: 2,666 posts

Joined: Dec 2004

Not sure if this is the only thing, but you forgot a period

include("/articles/".$article".txt");

should be

include("/articles/".$article.".txt");

He has: 52 posts

Joined: Apr 2006

Works beautifully. Thanks.

Greg K's picture
Moderator

He has: 1,676 posts

Joined: Nov 2003

I would recommend also doing a check with file_exists before including it as well.

See http://us2.php.net/manual/en/function.file-exists.php for more info.

-Greg

[This space intentionally left blank]

Cool Geek Supplies: www.ThinkGeek.com

He has: 52 posts

Joined: Apr 2006

Yes, after some researching, I have come to use that function, as well. Thank you.

Subscribe to this feed: Syndicate content