...

View Full Version : Functions Problem : /



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


<?php
session_start();

?><html>
<title>Login System</title>
<body>
Welcome to the login system.<br><br>
<?php
$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' />
</form><br>";
}

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




?>

</body>
</html>

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?

Fumigator
03-16-2007, 09: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().

aedrin
03-16-2007, 11:00 PM
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"?

ole90
03-17-2007, 04: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!

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

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

Nightfire
03-17-2007, 08: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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum