View Full Version : Functions Problem : /

03-16-2007, 09:43 PM
So heres my code:


<title>Login System</title>
Welcome to the login system.<br><br>
$user3 = $_SESSION['username'];
$pass3 = $_SESSION['password'];
function ilogin()
echo"<form action='loginprocess.php' method='POST'>
Username: <input type='Text' name='username' value='Username' /><br />
Password: <input type='password' name='pword' /><br />
<input type='Submit' value='Log In' />

if(!$user3 && !$pass3) {
echo "Welcome Guest, please login";
echo "<a href='register.php'>Register!</a><br><br>";
echo "Welcome $username, please continue!";



It's very simple, i'm only testing it out. But, the error i'm getting is that the function ilogin(); does not display the form i have declared in the function above it. All i get is a blank space.

Anything i'm doing wrong =X?

03-16-2007, 10:10 PM
if(!$user3 && !$pass3) {

What are you really trying to do here? As you have it, you are checking these variables as if they were boolean variables (i.e. either true or false) but that's not how you are assigning them.

If you want to see if they exist, use isset() and if you want to see if they are empty, use empty(), but beware values of 0 will be seen as empty if you use empty().

03-17-2007, 12:00 AM
Also, it's not proper to echo out things from a function. Have the function return the output, then use echo ilogin().

Are you seeing the text "Welcome Guest, please login"?

03-17-2007, 05:11 PM
what do you mean have the function return the output? Explain with an example please.

Also, i fixed it using isset. Thank you!

03-17-2007, 09:17 PM
You don't need a function there at all, just move the HTML into your if().

03-17-2007, 09:18 PM
But i'd rather have it as a function as i might have to output the form a number of times.

03-17-2007, 09:39 PM
If you need to use it in different places, make a global included file - one with your functions etc in and just put the html into a variable and call the variable whenever you need the form. The function isn't doing anything so isn't really neccesary