Jump to content

[SOLVED] if(!isset($_GET['country_id'])){ - head hurts


aerophilia

Recommended Posts

Hi,

php newb here.

Quick "easy" question for you. It has been hurting my head this last hour.

 

What I want to do: if my URL has "?country_id=2" have my text appear on the page.

 

if(!isset($_GET['country_id'])){
		if($country_id=="2"){
			echo $europe_austria_txt;
		}
}

 

for further information here's "$europe_austria_text"

$europe_austria_txt="
	<br />
	Here will be some great text about the wonderful place they call Austria<br />
";

 

Link to comment
https://forums.phpfreaks.com/topic/107962-solved-ifisset_getcountry_id-head-hurts/
Share on other sites

1.) You dont need the ! sign. That makes the statement read the opposite to what you want.

2.) Unless you extracted $country_id from the URL previously, then that is unset.

3.) You can do it all with one if statement:

 

if(isset($_GET['country_id']) && $_GET['country_id'] == 2){
    echo $europe_austria_txt;
}

 

Also, if you enclose your string in double quotes, then you can use \n to make a new line, rather than spreading it across multiple lines:

 

$europe_austria_txt="\n<br />Here will be some great text about the wonderful place they call Austria<br />\n";

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.