PDA

View Full Version : asp or php passing variables?


ianhull
06-10-2005, 05:21 AM
Hi guys,

I am trying to pass variables through my pages it can be asp or php, I have managed to pass "fname" to the next page but I would like page2 which retrieves this information to store it in a hidden field so that I can pass it to another page, any ideas on how to do this?

Thanks guys

Corey
06-10-2005, 05:24 AM
If it's in a form, that's easy. So for example our original link which leads from page 1 to page 2 might be:

http://www.yoursite.com/page1.php?name=Joe

Then on page 2 you simply add this to your HTML form:

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

:) :yes

rhosk
06-10-2005, 05:25 AM
Just off the cuff, I think a 'global function' should be able to handle that.

ianhull
06-10-2005, 05:35 AM
Excellent Corey, Once agin you are the man!

And thanks for that Rhosk, I will look into that.

Thanks again guys. :yes

rhosk
06-10-2005, 05:42 AM
Once again, Corey is quick on the fly. He mentioned that you were "talking web pages". That's what I get for reading/replying too quick. I was thinking too deep. Need more java I guess.

ianhull
06-10-2005, 06:12 AM
Hi again,

I seem to be having a little trouble with this one.

I can post to the first page which is called welcome.php but I cannot seem to post to welcome2.php as I have an error on line 5

I cannot seem to work it out.

<html>
<body>Welcome <?php echo $_POST["name"]; ?>.<br />
</body>
<form action="welcome2.php" method="POST">
<input type="hidden" name="name" value="<?php echo $name; ?>">
<input type="submit" />
</form>

</html>

Any more help will be greatly appreciated.

Thanks :huh

Corey
06-10-2005, 06:15 AM
Hi. In that case just use:

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

:yes :)

ianhull
06-10-2005, 06:22 AM
:yes :yes :yes

Excellent Corey.

Thanks again.

Corey
06-10-2005, 06:40 AM
Glad to help. :) :yes

ianhull
06-10-2005, 10:27 AM
Hi again guys,

I just have a little question about php and storing everything globally

I have used a include function on evey page and I am wondering if I enter my name and then retrieve it on page 3, then on page 4 if I have another input box which uses the var name "name" again wil it overwrite the stored var?

Thanks guys, and Ron thanks for your suggestion on globals it does keep everything nice and tidy and it is easier to learn with. :yes

Corey
06-10-2005, 02:02 PM
Yes it will, you can only use each variable name once if you wish the value to hold, or at least you would have to shift the value to another variable/array if you want to keep it but re-use the variable name. :)

It's the same as in AMS if you replace a variable value, the first one is lost, i.e.:

name = "Joe";
name = "Bob";

Will result in the variable called "name" containing the value "Bob". "Joe" is lost forever unless you shift it somewhere else, i.e.

names={};
name = "Joe";
names[1] = name;
name = "Bob";
names[2] = name;

Would result in the variable "name" containing the value "Bob" but the table "names" containing both "Joe" and "Bob"... Hope that helps. :)

ianhull
06-11-2005, 04:25 AM
Hey that's excellent Corey,

I did not know I could do that with the tables, You just saved me loads of time again.

Thank you very much

:yes

Corey
06-11-2005, 04:49 AM
No problem, for even more check out the free video on "Tables Made Easy" at:

http://www.speedytraining.com/site/cd3.php

:yes