Jump to content


Photo

exit


  • Please log in to reply
5 replies to this topic

#1 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 15 June 2006 - 12:01 AM

So here's what I got:

<?php
if(isset($_POST['a'])){
     if(empty($_POST['a'])){
        echo 'a is empty';
        exit;
     }
     echo 'yada yada yada';
}else{
   echo 'blah blah blah';
}

echo 'not in conditional';
?>
</body></html>

What's happening is that if a set but is empty, "a is empty" is echoed, but the page is completely blank after that. When a is set (and not empty), I want "yada yada yada", "not in conditional" and "</body></html>" to all be printed (that works as it is now). When a is set but empty, I want only "a is empty", "not in conditional" and "</body></html>" to be printed. I know I could just add "not in conditional" and "</body></html>" to the TRUE and FALSE of the main conditional, but is there an easier way?
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 15 June 2006 - 01:43 AM

exit() does as it claims. Why are you making this so elaberate?

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 15 June 2006 - 09:36 AM

exit will stop PHP from ruinning any code past the point you place the exit function, therefor nothing is outputted when you echo "a is empty".

#4 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 15 June 2006 - 06:00 PM

So is there a way to stop the script just from executing the parent conditional but printing everything else?
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 15 June 2006 - 06:28 PM

You'll want do this:
<?php
if(isset($_POST['a']))
{
     if(empty($_POST['a']))
    {
        echo 'a is empty';
    }
    else
    {
        echo 'yada yada yada';
    }
}
else
{
   echo 'blah blah blah';
}

echo 'not in conditional';
?>
</body></html>


#6 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 15 June 2006 - 08:10 PM

That's the only way to do it? Just wondering cause I always indent my conditionals and the bulk of the code would be in the first }else{ (where the "yada yada yada" is), which would make the code a little harder to read/write
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users