title: How to show php login errors?
body: <p>I'm working on a simple login system to improve my knowledge and I would like to know how I can show alert messages if user type the wrong password or username or he doesn't fill any fields, I've started with something but I'm not sure if it is the right way and I don't know how to show message in the page with the login form. Many thanks for your help :)</p>
  
  <p><strong>This is my login controller</strong></p>
  
  <pre><code>&lt;?php
  /**
   * Nome File : ctrl_login.php
   * Descrizione: File che gestisce i dati inseriti nella pagina di login
   */
  
  include('../config/konasi.php');
  include('functions.php');
  
  $user_name   = check_input($_POST['username']);
  $user_password = check_input($_POST['userpassword']);
  
  if (!$user_name || !$user_password) {
      echo "Non hai inserito username o password";
      exit();
  }
  
  if ($stmt = mysqli_prepare($conn, "SELECT user_password FROM users WHERE user_name= ? ")) {
      /* Bind parameters: s - string, b - blob, i - int, etc */
      $stmt -&gt; bind_param("s", $user_name);
      /* Execute it */
      $stmt -&gt; execute();
      /* Bind results */
      $stmt -&gt; bind_result($result);
      /* Fetch the value */
      $stmt -&gt; fetch();
      /* Close statement */
      $stmt -&gt; close();
  }
  
  if(password_verify($user_password, $result)) {    
      echo "you are connected!";    
  } else {        
      echo "Ops, wrong password";
  }
  
  mysqli_close($conn);
  </code></pre>
  
  <p><strong>This is my index file with the login form</strong></p>
  
  <pre><code>&lt;form class="form-signin" action="includes/ctrl_login.php" method="post"&gt;
      &lt;h3 class="form-signin-heading"&gt;Login &lt;/h3&gt;
  
      &lt;div class="form-group"&gt;
          &lt;label for="username" class="sr-only"&gt;Username &lt;/label&gt;
          &lt;input type="text" id="username" name="username" class="form-control" placeholder="Username"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label for="password" class="sr-only"&gt;Password&lt;/label&gt;
          &lt;input type="password" id="password" name="userpassword" class="form-control" placeholder="Password"&gt;
      &lt;/div&gt;
  
      &lt;button class="btn btn-lg btn-primary btn-block" type="submit"&gt;login&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>This is my function.php</strong></p>
  
  <pre><code>function check_input($data)
  {
      $data = trim($data);
      $data = stripslashes($data);
      $data = htmlspecialchars($data);
      return $data;
  }
  </code></pre>