PHP If and Else not working properly

The following PHP should determine ?purpose=emailif it exists , and then if it determines what sting contains ?emailaddressor not. If there is an email address, it runs one set of scripts, and if not another. But no matter what, it acts like emailaddress !== '';any idea why.

<?php if($_GET['purpose'] == 'email') {?>
<?php   if($_GET['emailaddress'] !== '') {?>
  <script type="text/javascript">
    alert('<?php echo $_GET['emailaddress'];?>');
    window.setTimeout(function(){
      $('.dirops .loadpanel div span', window.parent.document).html('Complete');
      $('.dirops .loadpanel', window.parent.document).removeClass('slideup');
    },1000);
  </script>
<?php } else { ?>
  <script type="text/javascript">
    window.setTimeout(function(){
      $('.dirops .loadpanel div span', window.parent.document).html('Loading');
      $('.dirops .confirmemail', window.parent.document).addClass('slideup');
    },1000);
    $('#confirmemail', window.parent.document).attr('href', 'http://www.golfbrowser.com/A4/directions.php?purpose=email&start=<?php echo $_GET['start'];?>&end=<?php echo $_GET['end'];?>')
  </script>
<?php   } ?> 
<?php } ?> 

Any ideas?

Wonderful

+5
source share
5 answers

Try if($_GET['emailaddress'] != '')i.e. !=instead!==

+4
source

Usage: array_key_exists('emailaddress', $_GET)instead$_GET['emailaddress'] !== ''

+3
source
if (isset($_GET['emailaddress'])) { ....
+1

- , /else ...

var_dump($_GET) isset($_GET['emailaddress']) .

+1

:

<?php if(array_key_exists('purpose', $_GET) && $_GET['purpose'] == 'email') {?>
<?php   if(array_key_exsist('emailaddress', $_GET) && $_GET['emailaddress'] != '') {?>
0

All Articles