There's no such thing as a stupid question, but they're the easiest to answer.


Web Design & Development Web Design & Development
Search Search
Search for:
Tech Support Guy > > >

PHP Passing Hidden Form Field


smooth's Avatar
Member with 4,016 posts.
Join Date: Sep 2005
Location: NC, USA
Experience: Learning everyday :)
10-Mar-2009, 07:33 AM #1
PHP Passing Hidden Form Field
Hey everybody

I have a php page with the following form on it:

PHP Code:
        <form action="" method="post">
        <input type="hidden" name="random" value="<?php echo $random?>" />
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <td align="center">
                        Code 1
                        <br />
                        <input name="code1" type="text" />
                    <td align="center">
                        Code 2
                        <br />
                        <input name="code2" type="text" />
                    <td align="center">
                        Code 3
                        <br />
                        <input name="code3" type="text" />
                     <td align="center">
                        Code 4
                        <br />
                          <input name="code4" type="text" />
                    <td align="center">
                        Code 5
                        <br />
                        <input name="code5" type="text" />
                    <td align="center">
                        Code 6
                        <br />
                        <input name="code6" type="text" />
                    <td colspan="3" align="center">
                        <br />
                        <input type="submit" name="submit" value="Submit" />
                        <input type="reset" name="reset" id="reset" value="Reset" />
In order to determine where the user goes when submitting the form, I have the following code at the top of the same page:

PHP Code:
$random rand(150000950000);
$strCode1 $_POST['code1'];
$strCode2 $_POST['code2'];
$strCode3 $_POST['code3'];
$strCode4 $_POST['code4'];
$strCode5 $_POST['code5'];
$strCode6 $_POST['code6'];

$code1 strtolower($strCode1);
$code2 strtolower($strCode2);
$code3 strtolower($strCode3);
$code4 strtolower($strCode4);
$code5 strtolower($strCode5);
$code6 strtolower($strCode6);

if ( 
$code1 == "this" && $code2 == "code" && $code3 == "works" && $code4 == "really" && $code5 == "well" && $code6 == "yay" ) { 
$_SESSION['confirmed'] = true;    
header('Location: yay.php');
} else {
$_SESSION['confirmed'] = false;
header('Location: boo.php');

That works perfectly, as far as getting the user to the correct page, based on if they put in the correct code or not.

However, what I want to do, is access the number that is generated by this line:

PHP Code:
<input type="hidden" name="random" value="<?php echo $random?>" />
on either "yay.php" or "boo.php".

I've tried $_GET and $_POST when trying to access it on those pages, but can't seem to get it right.

Any ideas or suggestions are greatly appreciated
MMJ's Avatar
MMJ MMJ is offline
Senior Member with 3,625 posts.
Join Date: Oct 2006
10-Mar-2009, 02:39 PM #2
Don't exactly follow.

$_POST['random'] isn't set?
dudeking's Avatar
dudeking dudeking is offline
Member with 483 posts.
Join Date: Feb 2007
Location: UK, Midlands
Experience: Advanced
10-Mar-2009, 06:05 PM #3
You may need an id and a name
thebeginner's Avatar
thebeginner thebeginner is offline
Computer Specs
Member with 29 posts.
Join Date: Feb 2008
Experience: Advanced
11-Mar-2009, 11:09 AM #4
When opening a dialog in Visual Basic, Visual C# or other programming languages Windows has to know the name of the dialog. This I believe is the case here. Instead though the ID and Name is needed. The server needs to know where to place the charactors. I believe it's the server that's involved here.
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

You Are Using: Server ID
Trusted Website Back to the Top ↑