Passing Variable through Forms

From: Date: Fri, 09 Jun 2000 23:12:23 +0000
Subject: Passing Variable through Forms
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-1501@lists.php.net to get a copy of this message
I have been having trouble passing a variable through a form when the form is case one of a swtich statement and the action of the form is case 2 of the same php script. The variable is reported as being empty when it is accesssed in case 2. When I make an html whose action is a php script that contains only the function used in case 2 it works fine but I will be expanding on this with multiple related forms and want to contain everything to one file. I'm sure that there is something real simple that I'm overlooking, I think it might have something to do with the scope of the variable, but I'm not sure what to do about it. you can see what is happening at www.rfcomsites.com/admin/index.php3 the script is attached. any help would be appreciated. Chad Morgan

<?php define (ENTER_PASSWORD, 0); define (CHECK_PASSWORD, 1); function enter_password(){ global $PHP_SELF; printf ("<FORM method = \"POST\" action=\"%s?action=%d\">\n", $PHP_SELF, CHECK_PASSWORD); echo ("<P>Enter Password: <INPUT TYPE=password SIZE=10 NAME=\"password\"</P>\n"); echo ("<P><INPUT TYPE=\"submit\" NAME=\"button\" VALUE=\"Submit\"></P>\n"); echo ("</FORM>"); } function check_password(){ if (empty($password)) die ("No Password"); if ($password == "1234") echo ("Password Correct"); else echo ("Password Invalid"); } if (empty($action)) $action = ENTER_PASSWORD; switch ($action) { case ENTER_PASSWORD: enter_password(); break; case CHECK_PASSWORD: check_password(); break; default: die ("Unknown Action Entered"); } ?>
« previous php.general (#1501) next »