Hi there,

I'm struggling to get a simple if statement to work. I am passing a country though to a page from a previous page ( ?country=Poland)
and then trying to evaluate it and display a specific bit of text if the country is for example'Germany'. Here's what I have:

<?php 
    	if ($_Get["country"]  = 'Germany') { echo "Company Name: Susensoftware AG<br />Contact Name: Axel Susen<br /><br />"; }
  ?>

But it is displaying the text even if the country isn't 'Germany' and I don't know why?!

Please laugh if I'm being dumb, but can anyone help?

Thanks in advance

Recommended Answers

All 5 Replies

if($_GET['country'] == "Germany")

You are missing another "=" in your statement.

Oops...

$_Get ["country"] = 'Germany' is setting it to Germany, not just evaluating the IF... so perhaps I need to set a variable and evaluate that instead...?

Am I on the right lines? Anybody ;)

:P Yeps! That's absolutely right!

= is an assignment operator where as, == is a comparison operator!

Thanks for the help! I added the extra "=" and used a variable and it worked properly:

$cvalue = $_GET["country"];
    	if ($cvalue  == 'Germany') { echo "Company Name: Susensoftware AG<br />Contact Name: Axel Susen<br /><br />"; }
if($_GET['country'] == "Germany")

You are missing another "=" in your statement.

:) Great! Cheers man..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.