...

View Full Version : Very simple but won't work



mwm
11-27-2006, 03:07 PM
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?


<html>
<form action="2.php" method="post">
<input type="hidden" name="id" value="mike">
<input type="submit">
</form>
</html>



<html><form action="3.php" method="post">
<?
//$id=$_POST['id'];
echo $id;
?>
<input type="submit">
</form>
</html>


<html>
<form>
<?
//$id=$_POST['id'];
echo $id;
echo "hi";
?>
</form>
</html>

Brandoe85
11-27-2006, 03: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.

Good luck;

GJay
11-27-2006, 03:18 PM
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.
for example:
page1.php


<?php
session_start();
echo $_SESSION['test']; //will either be blank, or give a 'notice' of undeclared variable
$_SESSION['test']='hello';
echo $_SESSION['test']; //will echo 'hello'
?>
<a href='/page2.php'>Page 2</a>

page2.php


<?php
session_start();
echo $_SESSION['test']; //will echo hello
unset($_SESSION['test']);
?>
<a href="/page3.php">Page 3</a>

page3.php:


<?php
//no session_start() this time
echo $_SESSION['test']; //session not starte, no nothing/notice again
?>

CFMaBiSmAd
11-27-2006, 05: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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum