Knowles

msg:1300780 | 1:15 am on Aug 28, 2002 (gmt 0) |
My best guess at for you to get a better understanding would be to read PHP: Variables - Manual [php.net] 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
|
jatar_k

msg:1300781 | 1:55 am on Aug 28, 2002 (gmt 0) |
Hello mapgeek, 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]
|
mapgeek

msg:1300782 | 3:23 pm on Aug 28, 2002 (gmt 0) |
OK. So, I think I'm on the verge of figuring this out. In my original post (PHP Form Handler page 2). I tried $_GET and it didn't work; however, $HTTP_GET_VARS did. In this case, $_ENV did work and $HTTP_ENV_VARS didn't. So what I think I am seeing is that when calling global variables from another source (ie in the first example from an html page), I use $HTTP_*_VARS. When calling global variables from within the same source I need to use $_*. Is this at all close to the truth? 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?
|
Knowles

msg:1300783 | 4:28 pm on Aug 28, 2002 (gmt 0) |
I am not sure what you mean on the first part of the post, I am sure someone can answer that. 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.
|
transistor

msg:1300784 | 4:29 pm on Aug 28, 2002 (gmt 0) |
Hi all. I've just started to made my move to Register_Globals=off and it's been quite a nightmare! I use PHP 4.2.2 and the $_* format to get my variables. Mapgeek: I use $_SERVER to get the variables you ask for with $_ENV. Honestly, I don't know what is the difference, but it works for me. As for your code, I believe that you are missing a <form> tag. If you do, then (depending on the method) you should get your variables from $_GET or $_POST. 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 :)
|
mapgeek

msg:1300785 | 5:24 pm on Aug 28, 2002 (gmt 0) |
I lied. That wasn't the whole code. There is a <FORM> tag. <FORM METHOD="POST" ACTION="p-5-1.php"> The ACTION is posting back into itself, meaning the file name of this script is the same as the ACTION. I tried using both $_POST and $HTTP_POST_VARS. Neither worked. I understand that the variables need to be defined before they are called. It's just that this guy did it this way in 3 exerceses, with the objective of showing how php statments can process data entered onto the form. So, I'm thinking there probably is a way to do it. I'm probably beating a dead horse because I don't know if I'll actually need to do this, but I am trying to get my mind wrapped around this.
|
Knowles

msg:1300786 | 5:40 pm on Aug 28, 2002 (gmt 0) |
Ok I am getting confused I think. What does this form do? It sounds like a caculator to me which is where my last post was thinking. Also maybe what is the tutorial your reading maybe that would help me get an understanding of what you are doing.
|
jatar_k

msg:1300787 | 5:50 pm on Aug 28, 2002 (gmt 0) |
This is getting a little confusing, I tested that little page. I added html, head, title, body, the form tag before the table tag and the closing form tag agter the close table. It works perfectly. I seem to be running php 4.0.6 with register_globals on.
|
jatar_k

msg:1300788 | 6:30 pm on Aug 28, 2002 (gmt 0) |
with out register_globals on you could throw the values into vars. $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.
|
mapgeek

msg:1300789 | 7:09 pm on Aug 28, 2002 (gmt 0) |
Well, it is a calculator. But using forms to show how to process data. I had a feeling it had something to do with globals on. I added the new variables, but to no avail. I used both $_ and $HTTP. The only difference is that have have a zero in the last text box. Back to the $_* and $HTTP_*_VARS question, is there any rule of thumb in deciding which variable to use besides trying one and then seeing if it works?
|
jatar_k

msg:1300790 | 7:12 pm on Aug 28, 2002 (gmt 0) |
before version 4.1.0 the $HTTP_ style. Later versions support both so it would depend on whether you want an autoglobal style ($_) or not($HTTP_). check sticky.
|
mapgeek

msg:1300791 | 7:13 pm on Aug 28, 2002 (gmt 0) |
oh, I forgot to tell you. I am working out of PHP4 A Beginner's Guide by Bill McCarty. Project 5-1.
|
dhdweb

msg:1300792 | 7:58 pm on Sep 1, 2002 (gmt 0) |
| <?= $OP1; ?> instead of <?echo $OP1; ?> |
| Shouldn't it be: <? = $OP1; ?> instead of <? echo $OP1; ?> with a space after and before the "<? " & " ?>"
|
jatar_k

msg:1300793 | 8:13 pm on Sep 1, 2002 (gmt 0) |
from php.net on echo [php.net] | echo() also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. |
|
|
|