Page 1 of 1

Problem with hidden variable

Posted: Thu Feb 03, 2005 1:28 am
by kkawalli
Hi EveryBody,
well i have some problem with the hidden variable....

the problem is

in one page i am inserting the details into database...on successfull insertion i am striring a message in varaiable like

$confirm="Information successfully Added";

so i am redirecting to another page using

<html>
<body onload="redirect.submit">
<form name="redirect" action="page2.php" method="post">
<input type="hidden" name="confirm" value="<? echo $confirm";?>>
</form>
</body>
</html>



so when i chk the variable $confirm in page2.php
and print the value only word "Information" is displayed ...

can anyone tell whats the problem
any alternate method...........

Posted: Thu Feb 03, 2005 1:39 am
by feyd
the code you posted will give a parse error.

Posted: Thu Feb 03, 2005 3:12 am
by CoderGoblin
In general when posting please provide as much consise information as possible.

I would guess that you need to look up http://www.php.net/urlencode when creating the parameter. If you are using sessions I would store the variable in a session.

Unless you have register globals on in php (not default and not recommended) you need to get the variable using $_POST['confirm'] rather than just $confirm.

Posted: Thu Feb 03, 2005 4:45 am
by Black Unicorn
There are 2 obvious problems. First,

Code: Select all

<body onload = "redirect.submit">
Needs to be

Code: Select all

<body onload = "redirect.submit()">
and your hidden variable needs to be

Code: Select all

<input type="hidden" name="confirm" value="<?=$confirm ?>" />
It has already been said, better to provide too much contextual info rather than too little.
Regards,
H

Posted: Thu Feb 03, 2005 6:22 am
by John Cartwright
Black Unicorn wrote:There are 2 obvious problems. First,

Code: Select all

<input type="hidden" name="confirm" value="<?=$confirm ?>" />


Not every server has shorttags enabled, and it is not a requirement to use them. It's always better to be safe