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
    Jun 2008
    Posts
    104
    Thanks
    71
    Thanked 0 Times in 0 Posts

    Lightbulb Help with IF statements

    I'm trying to redirect a user to another page based on a certain condition.

    However, for some reason, it doesn't redirect and it keeps returning the else statement.

    Here's my code:

    Code:
    if (mysql_num_rows($result) == 1 && $userpass == $userData['password']){
    
      if ($userData['active'] == '1'){
    
      header('Location: members.php');
    
      }
    
      if ($userData['active'] == '0'){
    
      header('Location: payment.php');
    
      }
    
    }
    else{
    echo ("Login failure! Please try again.");
    }
    When I remove the two nested IF statements, it works fine. Any ideas?

    Thanks!

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    What output do you get for the following ?
    PHP Code:
     print_r($userData); 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    four0four (02-15-2010)

  • #3
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,472
    Thanks
    13
    Thanked 361 Times in 357 Posts
    usually you have to exit the script after you make a header redirect.

  • Users who have thanked Dormilich for this post:

    four0four (02-15-2010)

  • #4
    New Coder
    Join Date
    Mar 2009
    Posts
    25
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Tell me what you see when you replace your above code with this:

    PHP Code:
    if (mysql_num_rows($result) == && $userpass == $userData['password']){

      if (
    $userData['active'] == '1'){

      echo 
    'If you see this, I know your problem.';

      }

      if (
    $userData['active'] == '0'){

      echo 
    'If you see this, I know your problem.';

      }

    }
    else{
    echo (
    "Login failure! Please try again.");

    I think you can't make header requests after any information is sent to the browser...

    -Sam

  • Users who have thanked thekooliest for this post:

    four0four (02-15-2010)

  • #5
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,472
    Thanks
    13
    Thanked 361 Times in 357 Posts
    Quote Originally Posted by thekooliest View Post
    I think you can't make header requests after any information is sent to the browser...
    you can, although that triggers an error (or warning?).

  • Users who have thanked Dormilich for this post:

    four0four (02-15-2010)

  • #6
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by Dormilich View Post
    you can, although that triggers an error (or warning?).
    It'll log an error and the header won't be sent. Output buffering can be used to prevent that particular scenario arising, however.

  • #7
    Regular Coder hdewantara's Avatar
    Join Date
    Aug 2009
    Location
    Jakarta, Indonesia.
    Posts
    375
    Thanks
    9
    Thanked 55 Times in 54 Posts
    Hi four0four:

    header('Location: members.php'); should be written as:
    PHP Code:
    header('Location: http://www.absolute.url/members.php'); 
    Not sure whether this would fix your problem but it is HTTP/ 1.1 requirement.


  •  

    Posting Permissions

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