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


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:


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

The combination you have between isset and == doesn’t seem correct to me.
Try rewriting your if like this:

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.

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.