View previous topic :: View next topic |
Author |
Message |
kev1952 -
Joined: 08 Sep 2005 Posts: 105 Location: Townsville Australia
|
Posted: Thu Feb 16, 2006 12:59 am Post subject: Using Include |
|
|
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 |
|
|
MonkeyNation -
Joined: 05 Feb 2005 Posts: 921 Location: Cardiff
|
Posted: Thu Feb 16, 2006 1:15 am Post subject: |
|
|
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 |
|
|
kev1952 -
Joined: 08 Sep 2005 Posts: 105 Location: Townsville Australia
|
Posted: Thu Feb 16, 2006 2:59 am Post subject: |
|
|
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 |
|
|
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Thu Feb 16, 2006 3:20 am Post subject: |
|
|
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 |
|
|
p3 -
Joined: 17 Jun 2005 Posts: 615
|
Posted: Thu Feb 16, 2006 4:04 am Post subject: Re: Using Include |
|
|
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 |
|
|
kev1952 -
Joined: 08 Sep 2005 Posts: 105 Location: Townsville Australia
|
Posted: Thu Feb 16, 2006 4:08 am Post subject: |
|
|
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 |
|
|
MonkeyNation -
Joined: 05 Feb 2005 Posts: 921 Location: Cardiff
|
Posted: Thu Feb 16, 2006 5:06 am Post subject: |
|
|
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 |
|
|
kev1952 -
Joined: 08 Sep 2005 Posts: 105 Location: Townsville Australia
|
Posted: Thu Feb 16, 2006 5:23 am Post subject: |
|
|
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 |
|
|
|