Seeing var in one page created in another page(form)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Twayne
Forum Newbie
Posts: 14
Joined: Fri Jun 20, 2008 11:47 am

Seeing var in one page created in another page(form)

Post by Twayne »

Hi,

Rank newbie here; sandboxxing with forms; XP Pro SP2 PHP 4.4, local Apache server setup. First post to this forum.

Have a file called entry.php:
In it, I generate a random number $num. Visitor is then to copy that number into a textbox via <input ... "pw"..>. Post is to another "check" file called check.php.

check.php sees "$pw" fine. But it turns out I don't know how to post the original "$num" var forward in order to compare it to "pw" to see if correct characters were input.

Relevant code stubs are attached. All this part is for is to validate the user copies the correct random number into the textbox.

Any hints?

TIA

I attached two files and "Added" them but see no evidence of them; hope they made it in.
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

Re: Seeing var in one page created in another page(form)

Post by nowaydown1 »

Greetings and welcome to the forum. I didn't see your code attached but I can give you a rough overview of what should take place. If you want to do a comparison to the original number generated, you should place that number in the session. Then, on your check.php page, just reference what should be set in the session already to see if it matches the value entered by the user.

Have you worked with sessions before? If not, sessions are used to maintain state between pages. You can read more about working with sessions at:

http://www.php.net/session

I would Google around some too. There's some decent tutorials around.
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: Seeing var in one page created in another page(form)

Post by WebbieDave »

If all that is required is that a visitor copies the shown number into a textbox, an alternative method would be to place the number in the form as a hidden input:

Code: Select all

<input type="hidden" name="num" value="<?php echo $num?>">
Post Reply