Problem with hidden variable

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
kkawalli
Forum Newbie
Posts: 2
Joined: Thu Jan 27, 2005 7:09 am

Problem with hidden variable

Post 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...........
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the code you posted will give a parse error.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
Black Unicorn
Forum Commoner
Posts: 48
Joined: Mon Jun 16, 2003 9:19 am
Location: United Kingdom

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
Post Reply