View Full Version : Very simple but won't work
I'm just doing a test to see if I can pass the variable "mike" from page to page. I can echo it out on 2.php but not on 3.php. What am I doing wrong?
<form action="2.php" method="post">
<input type="hidden" name="id" value="mike">
<html><form action="3.php" method="post">
11-27-2006, 04:16 PM
It won't be on page 3 unless you put it in a hidden field on 2.php. If you're going by multiple pages I think you'd enjoy using sessions instead of hidden fields.
values not in input tags (or selects or textareas) within a form won't get passed when the form is submitted. Your second page doesn't contain any inputs other than the submit, so nothing will be passed.
One way of doing what you want it to use 'sessions'. This is a method whereby you can preserve information on the server between page loads for a particular visitor.
echo $_SESSION['test']; //will either be blank, or give a 'notice' of undeclared variable
echo $_SESSION['test']; //will echo 'hello'
<a href='/page2.php'>Page 2</a>
echo $_SESSION['test']; //will echo hello
<a href="/page3.php">Page 3</a>
//no session_start() this time
echo $_SESSION['test']; //session not starte, no nothing/notice again
11-27-2006, 06:52 PM
Ahhh... you have the thread where an id is not carrying over between pages.
In addition to the lack of a hidden input field in the form, you also need to access the value received from the previous form page using $_POST['id']; (Using just $id would work if register_globals are on, but the hidden input field is still needed in either case.) If you are checking out the bogus information someone posted in that other thread about variables carrying over between pages, well that was bogus, web servers don't work that way.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.