title: How to display login error message on the same page in a php based system?
body: <p>I am building a php based login system where the user is required to put in a username and password for logging in. My question is 'how can I display the 'invalid username or password' error message on the same page'? I have tried many things including trying to use a query string (/?error=1); it did solve my problem by displaying the error message on the same page but all the CSS was just gone from the page and I couldn't find a way to fix it (not for the lack of trying, though). So I decided to try a simpler method which, obviously, did not work. 
  So, how can I fix it?
  Here's my PHP code:</p>
  
  <pre><code>&lt;?php
  session_start();
  $db = mysqli_connect("localhost","root","","combination");
  if(isset($_POST['login_btn'])){
  
      $username = mysql_real_escape_string($_POST['username']);
      $password = mysql_real_escape_string($_POST['password']);
  
      $password=md5($password);
      $sqlquery="SELECT * FROM registration WHERE username='$username' AND password='$password'";
      $result = mysqli_query($db,$sqlquery);
  
  
      if(mysqli_num_rows($result)==1){
  
          $_SESSION['message']="You are now logged in.";
          $_SESSION['username'] = $username;
          $_SESSION['password'] = $password;
  
          header("location:loginhome.php");
      }
      else{
          $_SESSION['message']="Incorrect Username or Password."; 
          header("location:login.php");
          echo '&lt;h3&gt;Invalid username or password&lt;/h3&gt;';
      }
  
  }
  ?&gt;
  </code></pre>