title: Login script not working, displaying echo message
body: <p>I have a login script written in PHP. If the username or password is incorrect, it will echo 'Username or password is invalid', which is currently what's happening (even though the username and password is correct)</p>
  
  <p>Here's my PHP code:</p>
  
  <pre><code>&lt;form method="POST"&gt;
  &lt;input type="text" name="username"&gt;
  &lt;input type="password" name="password"&gt;
  &lt;input type="submit" name="submit"&gt;
  &lt;/form&gt;
  
  &lt;?php
  
  $con = mysqli_connect("localhost","dbuser","dbpass","dbname");
  
  if(isset($_POST['submit'])) {
  
  $username = $_POST['username'];
  $password = $_POST['password'];
  
  $username = mysqli_real_escape_string($con, $username);
  $password = mysqli_real_escape_string($con, $password);
  
  $logincheck = mysqli_connect($con, "SELECT * FROM `users` WHERE username='$username' and password='$password'");
  $result = mysqli_query($con, $logincheck);
  $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
  $count = mysqli_num_rows($result);
  if($count == 1){
  $_SESSION['login_user'] = $username;
  header('Location: index.php');
  }else{
  echo "Username or password is invalid.";
  }
  }
  ?&gt;
  </code></pre>