Current location: Hot Scripts Forums » Programming Languages » PHP » hidden variable problem


hidden variable problem

Reply
  #1 (permalink)  
Old 05-22-04, 07:30 PM
scorpioy scorpioy is offline
Newbie Coder
 
Join Date: May 2004
Location: CA
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
hidden variable problem

I tried to run the following code on my localhost, but the server says that 'seemform' is an undefiend variable. Does someone know what is wrong with this?

<html>
<head>
<title>Listing 10-4</title>
</head>
<body>
<?
// all double quotations in $form must be escaped,
// otherwise a parse error will occur
$form = "
<form action=\"listing10-4.php\" method=\"post\" name=\"form1\">
<input type=\"hidden\" name=\"seenform\" value=\"y\">
<b>Give us some information!</b><br>
Your Name:<br>
<input type=\"text\" name=\"name\" size=\"20\" maxlength=\"20\" value=\"\"><br>
Your Email:<br>
<input type=\"text\" name=\"email\" size=\"20\" maxlength=\"40\" value=\"\"><br>
<input type=\"submit\" value=\"subscribe!\">
</form>";
// If we haven't already seen the form ($seenform passed by hidden
// form value), show the form.
if ($seenform != "y"):
print "$form";
else :
print "Hi, $name!. Your email address is $email";
endif;
?>
</body>
</html>



Someone told me to use $_POST['seemform'], instead of saying undefined variable, the server says 'seemform' is undefined index. Could someone tell me what should be correct code in the above code?

Thanks
Reply With Quote
  #2 (permalink)  
Old 05-23-04, 05:19 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
try this IF statment:
PHP Code:

if (!isset($_POST['seenform'])): 

don't worry about the value of seenform, since it's static and never change..
also it's not good to rely on globals!

don't worry about notices, they are just..... notices
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]

Last edited by NeverMind; 05-23-04 at 06:18 AM.
Reply With Quote
Reply

Bookmarks


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Count problem kasic ASP.NET 1 10-20-04 12:23 AM
Upload Script Problem!!! seanknighton Perl 0 03-21-04 09:54 PM
Function and variable problem perleo PHP 1 02-11-04 08:52 PM
User Authentication and Session problem!!! askme PHP 1 02-06-04 09:10 AM
Small problem for a pro, but for novice like me... argh! ntek Perl 3 11-19-03 01:45 PM


All times are GMT -5. The time now is 10:35 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.