Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Functions Problem : /

    So heres my code:

    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?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    PHP Code:
    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().

  • #3
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    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"?

  • #4
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts
    what do you mean have the function return the output? Explain with an example please.

    Also, i fixed it using isset. Thank you!

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    You don't need a function there at all, just move the HTML into your if().

  • #6
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts
    But i'd rather have it as a function as i might have to output the form a number of times.

  • #7
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •