Using Include

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
kev1952
-


Joined: 08 Sep 2005
Posts: 105
Location: Townsville Australia

PostPosted: Thu Feb 16, 2006 12:59 am    Post subject: Using Include Reply with quote

Can someone tell me why this doesn't work:
Code:
<?
include "test.php?p=2";
?>

while this does:
Code:
<a href="test.php?p=2">Test</a>

I'm trying to pass a value from a drop down form to a PHP script. The "include" works fine without the "?p=2" added to it but I need the value passed for another "include" in the target page script to work properly.
_________________
Cheers.... Kev

Kev's Place - http://www.kevsplace.com

Powered by Abyss X1.
Back to top View user's profile Send private message Send e-mail Visit poster's website
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Thu Feb 16, 2006 1:15 am    Post subject: Reply with quote

I'm not sure what you think include() does, but all it does is "insert" the contents of a file, you can't use a query string on that file either (?x=y).
If you're just trying to pass the p variable over, you don't need to do anything. Using include() is just like taking the source of the file and pasting it onto the line where the function resides. This could help.
_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
kev1952
-


Joined: 08 Sep 2005
Posts: 105
Location: Townsville Australia

PostPosted: Thu Feb 16, 2006 2:59 am    Post subject: Reply with quote

I understand what "include" does and I thought that it wouldn't accept an additional parameter. So, to pass a value I imagine the code would be something like this:
Code:
<?
$p="3";
include "test.php";
?>

and the value of $p should be available to the "included" document. Is this the correct way to do it or is there another way?

I just tried it this way and, yes, it does work.
_________________
Cheers.... Kev

Kev's Place - http://www.kevsplace.com

Powered by Abyss X1.
Back to top View user's profile Send private message Send e-mail Visit poster's website
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Thu Feb 16, 2006 3:20 am    Post subject: Reply with quote

include() is used only to include content from another file; if all your trying to
do is pass the value from $p to your script. You can use the example below....

Code:

<?php
if ($_GET["submit"]) {
 $p = $_GET["p"]; //$p has a value

 include("test.php");
}
?>
<form action="" method="get">
 <select name="p">
  <option value="value1">Option 01</option>
  <option value="value2">Option 02</option>
 </select>
 <input type="submit" name="submit" value="Go There!">
</form>

The value of $p is now filled in once submited. Now you can use the
value from $p and use it in your included page "test.php". Hope this
is what you're looking for. Im pretty sure this will work.

Sincerely, TRUSTpunk
Back to top View user's profile Send private message Visit poster's website
p3
-


Joined: 17 Jun 2005
Posts: 615

PostPosted: Thu Feb 16, 2006 4:04 am    Post subject: Re: Using Include Reply with quote

kev1952 wrote:
Can someone tell me why this doesn't work:
Code:
<?
include "test.php?p=2";
?>


Try this instead:
Code:

<?php
include('test.php?p=2');
?>
Back to top View user's profile Send private message Send e-mail
kev1952
-


Joined: 08 Sep 2005
Posts: 105
Location: Townsville Australia

PostPosted: Thu Feb 16, 2006 4:08 am    Post subject: Reply with quote

Thanks, TP. I've already done it all with a similar piece of code and it now works magnificently. Thanks for taking the time.

P3 - Unfortunately I had already tried that method and it failed miserably. :(
_________________
Cheers.... Kev

Kev's Place - http://www.kevsplace.com

Powered by Abyss X1.
Back to top View user's profile Send private message Send e-mail Visit poster's website
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Thu Feb 16, 2006 5:06 am    Post subject: Reply with quote

Including test.php?p=2 won't work, because there's no file called test.php?p=2.
There's a file called test.php, which when sent by the web server, adds an environment variable for the query string, which in turn, makes $_GET (Including others.); but no test.php?p=2.
_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
kev1952
-


Joined: 08 Sep 2005
Posts: 105
Location: Townsville Australia

PostPosted: Thu Feb 16, 2006 5:23 am    Post subject: Reply with quote

Thanks, MN. That's the way I looked at it too.
_________________
Cheers.... Kev

Kev's Place - http://www.kevsplace.com

Powered by Abyss X1.
Back to top View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group