Forum Moderators: coopster
I get everything right except for Remote Host which is the Undefined index error. Another question on this. If I do phpinfo() The names of the variable names are _Server["HTTP_REFERER"], etc. how do we translate that into what we want to see? What is the difference, for example, between $_GET and $HTTP_GET_VARS?
My second script, I don't even now how to begin to fix. The code is:
<TABLE>
<TR>
<TD><INPUT TYPE="TEXT" NAME="OP1" VALUE="<?echo $OP1; ?>"</TD>
<TR>
<TD ALIGN="CENTER">+</TD>
<TR><TD><INPUT TYPE="TEXT" NAME="OP2"
VALUE="<? echo $OP2; ?>"</TD>
<TR>
<TD ALIGN="CENTER"><INPUT TYPE="SUBMIT" VALUE="="></TD>
<TR>
<TD><INPUT TYPE="TEXT" NAME="RESULT" VALUE="<? echo $OP1 + $OP2; ?>"
disabled></TD>
</TR>
</TABLE>
The error messages (Undefined variables) appear in the text boxes.
I am more interested in the "inner workings" of variables, than quick code to fix the problems. Any help supplied will be greatly appreciated.
The problem your having in your script is your not defining $OP1 $OP2, with out a definition they dont know what the value of it is. You have to define it before you call it unless its a global varible which is predefined. So basically somewhere you have to say $OP1 = "OP1"; and $OP2 = "OP2"; as you know there are different ways for doing that.
Hope this helped,
Knowles
I'll start with the link where most of this info came from
[php.net...]
There a lot of different vars of similar format
$_GET and $HTTP_GET_VARS
$_POST and $HTTP_POST_VARS
$_ENV and $HTTP_ENV_VARS
$_SERVER and $HTTP_SERVER_VARS
$_SESSION and $HTTP_SESSION_VARS
etc.
the $_ types were all introduced in 4.1.0, all earlier version must use their $HTTP counterparts.
From the above link in re ENV
$HTTP_ENV_VARS contains the same initial information (as $_ENV), but is not an autoglobal. (Note that HTTP_ENV_VARS and $_ENV are different variables and that PHP handles them as such)
I actually couldn't find anything about $REMOTE_HOST I know that you can do it a different way.
$host = gethostbyaddr($_ENV['REMOTE_ADDR']);
Second Script
Where do $OP1 and $OP2 come from? Are they set higher up in the script? or posted? or something else?
I will give you a little trick. When you just want to echo a var value you can do
<?= $OP1; ?>
instead of
<?echo $OP1; ?>
On first looking at it I don't see any reason why it wouldn't work as is.
I didn't understand this
>>how do we translate that into what we want to see?
[edit]changed link[/edit]
For the second code, that's the whole script. The script is supposed to bring up 3 text boxs, a "+" sign and an "=" button. The user enters numbers into the first 2 boxes, presses = and the answer is supposed to appear in the last box. So I'm guessing that $OP1 and $OP2 are supposed to be globals. Is this where $GLOBALS or globals come in?
On the second question, no those would not be global variables. Global variables are predefined. You have never defined $OP1 & 2, so this is the reason for your error of undefined variable. Where you are echoing them in the first two text boxes you shouldnt be because thats where they get defined, the value portion of that box means what ever is there will display in the box value=44 would mean the text box would show 44. If you have a preset number you expect to use for $OP1 & 2 then place that as a value and if the user wants to change it they can since its a text box. Then when they hit the submit (or equal) button it will assign name=OP1 to $OP1 and the same for OP2. This will cause the action you are wanting to happen to happen in the 3rd text box.
As for why sometimes $HTTP_*_VARS works and sometimes $_*, I don't know.
If you are using PHP 4.1.0+ (and you say you are), using $_* should be enough.
But then again, I'm starting on this stuff myself :)
$OP1 = $HTTP_POST_VARS["OP1"];
$OP2 = $HTTP_POST_VARS["OP2"];
and then use all the same form code.
I really don't understand why the $_ and $HTTP_ are sometimes working or not. My only thought is conifguration. Not really sure though.
echo() also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign.