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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cant Find The Bug In My IF statement

    I'm quite new to PHP this has been wracking my brain, i did have this working when i just had an if and an else in the IF statement since I've added the else if its not been working i tried taking the else if out and then it still didn't work so i put it back in can someone spot what's wrong.

    There is no error returned by PHP but whatever is entered in the user name box it always prints "Welcome Super Cool Admin Man How are you!"

    PHP Code:
    <script language="php">
    $welcome_text="<font face=\"Arial\" size=\"2\" color=\"#FF000\">Welcome To The Connect Zone</font>";
    $admin="admin";
    $askuser['askuser'];
    $blank="";
    print(
    $welcome_text);
    </script>

    <form action="well.php" method="get" name="askuser" target="_self" dir="ltr">
    <input type="text" name="askuser" value="Enter Username">
    <input type="submit" name="askuser" value="Go">
    </form>

    <script language="php">
    if ($askuser $admin){
    print(
    "<font face=\"Arial\" size=\"2\" color=\"#FF000\">Welcome Super Cool Admin Man How are you!</font>");
    }elseif (
    $askuser $blank){
    print(
    "<font face=\"Arial\" size=\"2\" color=\"#FF000\">Log In Using The Form Above</font>");
    }else{
    print(
    "<font face=\"Arial\" size=\"2\" color=\"#FF000\">Your Not The Admin, DIE!!!!</font>");
    }
    </script> 
    Last edited by eamondo; 10-19-2006 at 05:52 PM.

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    You're assigning instead of comparing. It should be:

    $askuser == $admin

    and

    $askuser == $blank

  • #3
    Regular Coder
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    9
    Thanked 1 Time in 1 Post
    yup... use double equals in if statements.

  • #4
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,385
    Thanks
    8
    Thanked 1,077 Times in 1,068 Posts
    eamondo,

    ... and besides the issue of your "if" statements,
    if this is a login script, you might want to look into
    using sessions/cookies. That way, when someone logs
    in, they will stay logged in no matter where they go,
    until they close their browser. With your method, when
    they exit your site and come back, they need to log in again.

  • #5
    Regular Coder
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    9
    Thanked 1 Time in 1 Post
    True...

    If you need help on a simmilar system, go to techtuts.com. They have a whole custom usersystem that they edit/addon everyday. Plus, they are php maniacs.


  •  

    Posting Permissions

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