title: How to check username and password matches the database values
body: <p>I'm really sorry if the question looks silly. But I've been trying for days to check my <code>username</code> and <code>password</code> in the database matches what I'm typing in the <code>html</code> page... This is my Login form...</p>
  
  <pre><code>&lt;form method="POST" action="Dashboard/Dashboard.php"&gt;
  
      &lt;div class="form-group md-form"&gt;
          &lt;!--&lt;input type="email" class="form-control" id="email" value="" placeholder="Enter email address"&gt;--&gt;
          &lt;i class="fa fa-user prefix grey-text"&gt;&lt;/i&gt;
          &lt;input name="username" id="username" type="text" class="form-control" required&gt;
          &lt;label for="defaultForm-email"&gt;Username&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class="form-group md-form"&gt;
          &lt;!--&lt;input type="password" class="form-control" id="password" value="" placeholder="Enter password"&gt;--&gt;
          &lt;i class="fa fa-lock prefix grey-text"&gt;&lt;/i&gt;
          &lt;input name="password" id="password" type="password"  class="form-control" required&gt;
          &lt;label for="defaultForm-pass"&gt;Your password&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class="text-center"&gt;
          &lt;button type="reset" class="btn btn-amber btn-sm"&gt;&lt;strong&gt;Reset&lt;/strong&gt;&lt;/button&gt;
          &lt;input type="submit" name="submit" id="submit" class="btn btn-green btn-sm" value="Sign in"&gt;                                           
      &lt;/div&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>And this is the code(<code>php</code>) I'm using in <code>Dashboard.php</code></p>
  
  <pre><code>&lt;?php
      $servername = "localhost";
      $username = "root";
      $password = "";
      $databaseName = "test";
  
      $conn = mysqli_connect($servername, $username, $password, $databaseName);
  
      $un = $_POST['username'];
      $pw = $_POST['password'];
      print $pass . "_" . $email;
  
      $query = mysqli_query($conn, "SELECT log_username,log_password FROM login WHERE log_username='$un' AND log_password='$pw'");
  
      $result_can = mysqli_query($conn, $query);
  
  
      while ($row = mysql_fetch_assoc($result_can)) {
  
  
          $check_username = $row['username'];
          $check_password = $row['password'];
      }
      if ($un == $check_username &amp;&amp; $pw == $check_password) {
          $message = "ok";
          echo "&lt;script type='text/javascript'&gt;alert('$message');&lt;/script&gt;";
          header("Location: Doctors.php");
      } else {
          $message = "No";
          echo "&lt;script type='text/javascript'&gt;alert('$message');&lt;/script&gt;";
          header("Location: Doctors.php");
      }
      ?&gt;
  </code></pre>
  
  <p>I really tried like thousands of times, but couldn't figure out where I went wrong... Can anyone please help me?</p>
  
  <p><strong>I know my code is open to SQL injection, but I don't care about it as this is a example I needed to show to my friends</strong> So neglect that part.</p>