It seems that you're using two different conventions here.  This is 
inconsistent, and confusing to me (at least, and possibly others trying 
to help you).  Let me show you what I am talking about:

On Wednesday, March 13, 2002, at 09:20  AM, John Gurley wrote:

> Sorry,
>     Didn't mean to keep everyone in the dark here is the code:

... snip ...

> <hr>
> <?
> echo $inp;
> ?>

Okay, see above?  You've used "$inp".  Now read on to another part of 
your code:

> <?php
> echo $inp;
> echo '<input name = "inp" type = "hidden" value = 
> "'.$_POST['$inp'].'">';
> ?>

Okay, now here, you're echoing "$inp" again, but then in the second echo 
statement you are echoing "$_POST['$inp']"

Please don't be insulted if I make an assumption about what you know 
about the use of variables within scripts, I'm going to do my best to 
explain this and I can't know how much you know or don't.  Here's how it 

On a script, you have access to any variable that you create within that 
script.  Thus, if you create a variable named "$inp", you can then echo 
that variable or manipulate it in any way.  Like this:

$inp = "blue";   // this assigns the string "blue" to the $inp variable
echo $inp;   // this echoes "blue"
$outp = "green";  // this assigns "green" (a string) to the $outp 
$outp . $inp;   // this combines ("concatenates") the two variables 
                 // and results in the string "greenblue"

Okay, you probably already know all of that.  But my point is that these 
variables are accessible to this particular script.  NOT TO OTHER 
SCRIPTS.  If you need a variable to be accessible to another script, you 
must "pass" the variable along.  There are a few ways to do this:

1) You can make the value of this variable a form field value, like this:
echo "<input type=\"hidden\" name=\"inp\" value=\"$inp\" />";
(or this way, with single quotes:)
echo '<input type="hidden" name="inp" value="' . $inp . '" />';
note that in the above example, I have jumped out of the string being 
echoed and concatenated the $inp variable to the string, then 
concatenated the last part of the string ('" />').  This is because 
within single-quotes, variables won't expand -- the buck ($) is treated 
as a literal buck, not a variable marker.

2) You can put the variable name and value into the querystring of a 
hyperlink, like this:
echo "<a href=\"./form2?inp=$inp\">Next</a>";
(or this way, with single quotes:)
echo '<a href="./form2?inp=' . $inp . '">Next</a>';
see how I've again jumped out of the singlequoted string and 
concatenated the variable?  Same reason -- variables don't expand within 
singlequoted strings (though they do within doublequoted strings).

3) You can put the variable's value into a session variable.  How you do 
this depends on which version of PHP you are using.  You can learn more 
about session variables later, it's easy but you should get the hidden 
form field technique or querystring technique down first.

These are ways you can pass variables to other scripts.  Ignore the 
session bit if you haven't yet learned sessions.

So in your example, you are echoing the value of $inp.  But I don't see 
where you've done the ASSIGNMENT of any value to $inp.  For this reason, 
you will simply get an empty string:

echo $inp;   // this results in nothing
echo "<input type=\"hidden\" name=\"inp\" value=\"$inp\" />;
       // this results in '<input type="hidden" name="inp" value="" />'

If you had passed the $inp variable from a previous script to this one, 
then you would use either $_GET['inp'] or $_POST['inp'] to access the 
variable, assuming you have register_globals turned off in your php.ini 
(if you don't then don't worry about this).

echo $_POST['inp']; // if the form from the previous script was 
echo $_GET['inp'];  // if the form from the previous script was 

But if you do this:

echo $_POST['$inp'];

Then nothing will happen because the $inp part is between single quotes, 
and single quotes don't expand variables -- the buck is treated as part 
of the variable name (when it's not, it's supposed to be an indicator).

Even this:

echo $_POST["$inp"];

probably won't do what you want, because what will happen is the 
variable $inp (inside of the brackets) will evaluate first, and then 
whatever that evaluates to will become the name within $_POST['   
and    '].  Unless you have defined "$inp" somewhere, that's just a 
mistake.  Don't use the $ symbol within $_POST or $_GET variables until 
you have a reason to do so.

So, in your script, you've called the "inp" variable both $inp and 
$_POST['$inp'].  You probably really only want to use one or the 
other -- use the first one if register_globals is turned on, and the 
second one if register_globals is turned off.  But remember, this trick 
is used only for accessing variables that have been passed to this 
script from another script, not for accessing variables that have been 
defined within this script.

This may have been overly explanatory and confusing, but if you have a 
question about it, ask us.



Erik Price
Web Developer Temp
Media Lab, H.H. Brown

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to