Forums

PHP

This topic is locked

variables

Posted 30 Jul 2001 15:37:48
1
has voted
30 Jul 2001 15:37:48 Keith Slater posted:
Can anyone help with me with variables? I want it to remember what a person types in a field. Also whats the command to pull that variable up on another page.

Thanks

Keith Slater
Word Pro Systems
www.wordprosys.com

Replies

Replied 30 Jul 2001 17:15:27
30 Jul 2001 17:15:27 Tim Green replied:
There are a few ways to pass variables from one page to another. It really depends on the situation, as to which method you choose.

The easiest way to pass a variable on to the next page is to include as part of the URL. For example, if you wanted to pass the variable $timezone to the page watch.php you would use this in the HTML link :-

watch.php?timezone=<?php echo $timezone; ?>

This uses PHP to add the value of $timezone to the end of the URL.

On the page watch.php you would refer to that variable in one of two ways :-

$timezone or
$HTTP_GET_VARS["timezone"]

Both have the same effect, but it is possible that the fist method won't work. Depending on the configuration of your server.

This is all well and good. But you wouldn't want to use this method to transfer any sensitive information to the next page. This leaves you with a couple more choices. You can use session, or cookies, or indeed you could use a form.

If, in your case, you are using form variables, you can refer to the variable similarly.

You can either use :-

$formfieldname
$HTTP_GET_VARS["formfieldname"]
or
$HTTP_POST_VARS["formfieldname"]

I hope this is of some use to you.

Tim Green
Webmaster
www.rawveg.org (Coming Soon)
Replied 30 Jul 2001 17:19:20
30 Jul 2001 17:19:20 Keith Slater replied:
ok this goes along with that and this is something I've always wondered.. if a user logs in, it does the action <?php echo $KT_LoginAction?> and the only way I know how to pass stuff along to another page is to type the page URL in the action then it carries over. Is their another way to make it carry over?

thanks a lot rawveg, I appreciate it.

Keith Slater
Word Pro Systems
www.wordprosys.com
Replied 30 Jul 2001 19:42:43
30 Jul 2001 19:42:43 Tim Green replied:
Absolutely. Place a hidden form field in your form and do something like :-

<input name="myvariable" type="hidden" value="<?php echo $myValue; ?>">

When you click submit this value will be appended to the Action URL.

You can of course also include it as part of the action using :-

myaction.php?myVariable=myValue

as the action value.

Hope this helps.

Tim Green
Webmaster
www.rawveg.org (Coming Soon)
Replied 30 Jul 2001 19:53:39
30 Jul 2001 19:53:39 Keith Slater replied:
Thanks rawveg, it worked!

Keith Slater
Word Pro Systems
www.wordprosys.com

Reply to this topic