Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem: Function Undefined

Status
Not open for further replies.

alsaffar

Programmer
Oct 25, 2001
165
KW
I have a strange problem,

My script looks like this:

<?
if ($HTTP_SERVER_VARS['REQUEST_METHOD']!='POST')
{
?>
<html><body>
<form action=&quot;login.php?action=login&quot; method=&quot;post&quot;>
UserName: <input name=&quot;loginUserName&quot;><br>
Password: <input name=&quot;loginPassword&quot;><br>
<input type=&quot;submit&quot;>
</body></html>
<?
}
else
{
switch($action)
{
case login:
ProcessLogin();
die();
case logout:
die();
}
function ProcessLogin()
{
echo &quot;Im inside the function&quot;;
}
}
?>

I got the following error when I enter a UserName and a Pass:

Fatal error: Call to undefined function: processlogin() in /path/to/the/file/login.php on line 18

One more thing, although my method inside the html code is POST, when I tried to echo the value of $login I typed:

echo &quot;action: $HTTP_POST_VARS[action]&quot;;

it showed nothing !!!!

But when I typed:

echo &quot;action: $HTTP_GET_VARS[action]&quot;;

it showed action: login !!!!

Although when I typed

echo &quot;Method: $HTTP_SERVER_VARS[REQUEST_METHOD]&quot;;

it showed Method: POST !!!!

Come on, Its make no sense!!!

I tested it on my virtual server (Apache) and on my web server, the same crazy result I got.
 
put the function outside everything else at the bottome of the script and it'll work just fine.

<?
if ($HTTP_SERVER_VARS['REQUEST_METHOD']!='POST')
{
echo &quot;
<html><body>
<form action=\&quot;login.php?action=login\&quot; method=\&quot;post\&quot;>
UserName: <input name=\&quot;loginUserName\&quot;><br>
Password: <input name=\&quot;loginPassword\&quot;><br>
<input type=\&quot;submit\&quot;>
</body></html>
&quot;;
}
else
{
switch($action)
{
case login:
ProcessLogin();
die();
case logout:
die();
}
}

// functions down here
function ProcessLogin()
{
echo &quot;Im inside the function&quot;;

}

?> ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
The reason for the GET and POST vars, is that you specify your form's action as &quot;login.php?action=login&quot;, where action is a GET variable. You should use a hidden field, like
Code:
<input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;login&quot; />
This would work on all browsers, as the way you have it now, it _shouldn't_ even work. //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top