title: echoing wrong else in php
body: <p>Whenever I input wrong username, the resulting page gives the second else output. I want the first else to be displayed on the screen if a user types in wrong username and the second else to be displayed when someone tries to go in the login page directly from the url without inputting any name. And yes session_start(); has been declared on top of both the pages.</p>
  
  <pre><code>&lt;?php
  
  if (isset($_POST["submit"]))
      {
      $username = $_POST["username"];
      $conn = new mysqli("localhost", "root", "", "test");
      $result = $conn-&gt;query("select name from students where name = '$username'");
      if ($result-&gt;num_rows &gt; 0)
          {
          $_SESSION["username"] = $username;
          echo "You are logged in. This is the welcome page. Welcome user: " . $username;
          }
        else
          {
          echo "Invalid username. Try again.";
          }
  
      $conn-&gt;close();
      }
    else
      {
      echo "Come through proper ways.";
      }
  
  ?&gt;
  </code></pre>