SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict Normal75's Avatar
    Join Date
    Oct 2001
    Location
    Vancouver, Canada
    Posts
    245
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php if elseif else not working with rewrite rules

    I have the if/elseif/else statement as stated below and the idea is if I load the browser with domain.com/listing/email/12, I would execute the email function, if I load domain.com/listing/mortgage/12, mortageCalc() would be executed, etc.

    The problem is no matter which page I load, whether it's the email link (domain.com/listing/email/12), mortage link (domain.com/listing/mortgage/12) or visit link (domain.com/listing/visit/12), only the email function loads. I can't get the mortgage function to load when I go to domain.com/listing/mortgage/12 or the scheduleVisit function to load when I go to domain.com/listing/visit/12.

    Any help is appreciated.


    here is the php file
    PHP Code:
    if(isset($_GET['listingPage'])=='email'){
        
    email();
    }
    elseif(isset(
    $_GET['listingPage'])=='mortgage'){
        
    mortgageCalc();
    }
    elseif(isset(
    $_GET['listingPage'])=='visit'){
        
    scheduleVisit();
    }
    else{
        
    main();

    here is my .htaccess file:
    PHP Code:
    RewriteRule ^listing/email/([a-zA-Z0-9_-]+)$ /ctrl.php?throw=public/detail.php&lid=$1&listingPage=email
    RewriteRule 
    ^listing/mortgage/([a-zA-Z0-9_-]+)$ /ctrl.php?throw=public/detail.php&lid=$1&listingPage=mortgage
    RewriteRule 
    ^listing/visit/([a-zA-Z0-9_-]+)$ /ctrl.php?throw=public/detail.php&lid=$1&listingPage=visit 
    ~It will come to me one day~

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    The combination you have between isset and == doesn't seem correct to me.
    Try rewriting your if like this:
    PHP Code:
    if(isset($_GET['listingPage']) && $_GET['listingPage']=='email'){
        
    email();
    }
    elseif(isset(
    $_GET['listingPage']) && $_GET['listingPage']=='mortgage'){
        
    mortgageCalc();
    }
    elseif(isset(
    $_GET['listingPage']) && $_GET['listingPage']=='visit'){
        
    scheduleVisit();
    }
    else{
        
    main();

    Another thing to do in this case is a print_r($_GET); to see what values are being passed to the script.

  3. #3
    SitePoint Member
    Join Date
    Jan 2012
    Location
    Chennai
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    isset() function returns either "true" or "false"..that's why if/else code is not working..the workaround suggested by guido is the right one.


Tags for this Thread

Bookmarks

Posting Permissions

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