Forums: Back End:

 

PHP Switch

first
 

Napalm PHP Switch

I have 2 case statements on a site , $products and $page. Above that I have. Both cases defaults to the same page


$page = isset($_GET["page"]) ?$_GET["page"] : "default";
$product = isset($_GET["product"]) ?$_GET["product"] : "default";


The product one works, the page doesn't. Can someone urgently help me?

Thanks

Over the years I've come to realise my life is a Dilbert sketch
quote
 

Stickman

Just copied+pasted your code and it seems to work OK for me. Do you get an error? What URL are you using to test it?

I tried this:


$page = isset($_GET["page"]) ?$_GET["page"] : "default";
$product = isset($_GET["product"]) ?$_GET["product"] : "default";
echo( "$page : $product" );
exit;


With the following URLs and results:

StickBlog - random developer stuff
quote
 

the real me

hmm.. nothing wrong with the statement. are you sure page isn't getting set somehow? even if it's set to "" isset will return true.

so if your url ended up being something like "whatever.php?page=&product=12" isset would return true for both page and product.

might want to change it to something like


$page = (!$_GET["page"] && $_GET["page"] != "") ?$_GET["page"] : "default";


maybe? hard to tell what's going on without more code but the statement is fine.

 

Napalm

Thanks - the site was moved from a php 4 to a 5 server. The default was subsequently changed to this:


default:
if(empty($output)){
$output = "includes/home.htm";
$flash = "home.swf";
}
break;

Over the years I've come to realise my life is a Dilbert sketch
quote
 
first
 

Forums: Back End: PHP Switch

 
New Post
 
You must be logged in to post