title: Simple PHP form submitting - what's wrong with this conditional if and logical &&?
body: <p>The problem:</p>
  
  <p>if i submit the html form and a textbox is left blank<br>
  then i don't want it to proceed to the echo segment,<br>
  but the problem is it does proceed.</p>
  
  <pre><code>&lt;?php
          if(!isset($_POST['submit']) &amp;&amp; empty($_POST['moon']) &amp;&amp; empty($_POST['planet']))
          { 
  ?&gt;
  
          &lt;form name="form2" method="post" action="&lt;?php echo($_SERVER["PHP_SELF"]);?&gt;"&gt;
              &lt;div&gt;
                  Write a planet name: &lt;input name="planet" type="text"&gt;&lt;br&gt;
                  Its moon: &lt;input name="moon" type="text"&gt;
              &lt;/div&gt;
              &lt;div&gt;
                  &lt;input type="submit" name="submit" value="submit"&gt;
              &lt;/div&gt;
          &lt;/form&gt;
  
  
   &lt;?php
         }else{
  
              echo("Planet: ".$_POST['planet']. "&lt;br&gt;");
              echo("Moon: ". $_POST['moon'] . "&lt;br&gt;");
              echo "Successful.";
  
              }
  ?&gt;
  </code></pre>
  
  <p>As you know <code>isset()</code> determines if a variable is <code>set</code> and <code>not null</code> but doesn't check if it's empty.  </p>
  
  <p>While logic seems my if statement, I modified it from:<br>
  <code>if(!isset($_POST['submit']) &amp;&amp; empty($_POST['moon']) &amp;&amp; empty($_POST['planet']))</code></p>
  
  <p>To:</p>
  
  <ul>
  <li><code>if(!isset($_POST['submit'])  &amp;&amp; ($_POST['planet']=='') &amp;&amp; ($_POST['moon']==''))</code></li>
  <li><code>if(!isset($_POST['submit']))</code></li>
  <li><code>if(!isset($_POST['planet'])  &amp;&amp; !isset($_POST['moon']))</code></li>
  <li><code>if(empty($_POST['moon']) &amp;&amp; empty($_POST['planet']))</code></li>
  </ul>
  
  <p>and none of them worked.</p>
  
  <p><br>So am I doing something wrong with my if statement? how can I not let it proceed to the Else segment while a textbox is empty? without more if and no <code>nested</code> statements please.</p>