Jump to content

basic if/else problem


dirntknow

Recommended Posts

As a noob i'm sure there's good reason why this doesn't work but what i'd like to achieve is when a visitor opens a page it displays 'no organisation selected' and when they select one from a list (that coding works fine so i've left it out!) it puts ?orgname etc into the url...hope that makes sense!

....but this particular bit doesn't work!! Any suggestions most welcome, thanks!

 

<?php

if ($_GET['orgname']='') {

echo "no organisaton selected";

}

else {

echo $_GET['orgname'];

}

?>

Link to comment
https://forums.phpfreaks.com/topic/198776-basic-ifelse-problem/
Share on other sites

To explain why it doesn't work, it's because of this line:

 

if ($_GET['orgname']='') {

When comparing two values, you require at least 2 = signs. The statement you have above is ALWAYS true, because you're setting the value of $_GET['orgname'] to the empty string and that is always true. So there is really no comparison to be done.

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.