PDA

View Full Version : PHP help



NoWAyItZTOMmY
08-11-2009, 08:48 PM
okay need some help with php. i am trying to create a link '/index.php?id=dvd'
where dvd would be the page with the info, but i am getting

Warning: include(.txt) [function.include (http://som1600.x10hosting.com/function.include)]: failed to open stream: No such file or directory in

and i am using the code '<?php include ("$id.txt"); ?>' for this

what code do i use to have id=dvd pull up that file

Allshow97
08-12-2009, 07:18 AM
Well it looks like you are trying to use $id as a variable. Is that variable being passed from another page? Basically what you would have to do is pass the variable to this search result basically telling $id = (Whatever id number you put in the search bar).

Hope this helps.

NoWAyItZTOMmY
08-12-2009, 12:30 PM
okay i have a site with the main page index.php with a blank section, then when i click link
<a href="index.php?id=1">lala</a>

id=1 would open the same index.php but with the info it calls for from 1, 2, 3, ect ect.

what code would it be to use, i thought it would be
<?php include ("$id.txt"); ?>

Allshow97
08-12-2009, 05:52 PM
Oh ok I see now.

Try to single quote it.

so <?php include('$id.txt') ?>

PHP can be retarded sometimes...

Let me know if that works for you.

NoWAyItZTOMmY
08-12-2009, 09:22 PM
naw didnt happen

Allshow97
08-13-2009, 01:33 PM
Hrm its not passing the variable for some reason.

threehundred
09-03-2009, 07:52 AM
You have to first grab the $id variable from the URL using the GET function.

Near the top of the page (preferably in the <head> tags) add this:

<?php
$id = $_GET['id'];
$id = $id . ".txt";
?>


Then down where you want the content to be you do the include. The include should be structured this way (assuming the files to be included are something like 1.txt or 2.txt):


<?php
include($id);
?>

Allshow97
09-03-2009, 11:48 AM
You have to first grab the $id variable from the URL using the GET function.

Near the top of the page (preferably in the <head> tags) add this:

<?php
$id = $_GET['id'];
$id = $id . ".txt";
?>


Then down where you want the content to be you do the include. The include should be structured this way (assuming the files to be included are something like 1.txt or 2.txt):


<?php
include($id);
?>


Shows how long I haven't messed with PHP, I was at least right about it not retrieving the variable. Just forgot about the GET command :D