Re: Variables not working within Functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You are using a variable outside of the function's scope.
In the function, do this:
global $username;

Visit www.php.net/man to get a better understanding of globals and
scope.

On Wed, 2003-10-15 at 22:10, Adam Symonds wrote:
> Hi,
> I am starting to us functions with my work but I am having troubles
> With the variables in the functions..
> 
> If I have the following function called from my page it will work but the
> variable wont
> ($username)
> but if I put this code straight on the page then it works fine..
> 
> Any reason for the variable not to work in the function but in straight
> coding?
> Thanx
> 
> 
> 
> Sample Function Below:
> 
> ======================================
> function LoginSystem()
>  {
> echo "<div align=right>";
> if ( !isset( $_SESSION['login'] ) ) {
> 
> echo "<form action=../Users/Login.php method=post>";
> echo "<font size=1>Username: </font><input name=user type=text
> size=10>&nbsp;<font size=1>Password: </font><input name=pass type=password
> size=10>&nbsp;<input type=submit value=GO><br>";
> echo "<a href=../Register.php><font size=1>Not A Member
> Yet?</font></font></a>&nbsp;";
> echo "</form>";
> 
>  } else {
> echo "<font size=1>Welcome $username &nbsp;&nbsp;&nbsp;<a
> href=../Users/Logout.php><font
> size=1>Logout</a>&nbsp;&nbsp;&nbsp;</font></font><br><br>";
> }
> echo "</div>";
>  }

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux