title: mysqli query returns 0 results despite information in MySQL database
body: <p>I am in the process of making a login screen so once the session has been set a person can access various pages on my site.</p>
  
  <p>It seems, however, that when I send the username and password to be compared with what I have in the MySQL database the results come back empty.</p>
  
  <p><strong>MySQL table:</strong></p>
  
  <pre><code>Id, Username, Password, Email, group
  1,  bunbun, hashedpassword, example@email.com, admin
  </code></pre>
  
  <p><strong>PHP code:</strong></p>
  
  <pre><code>&lt;?php
  include_once("functions/con-open.php");
  
  if (isset($_POST['username']))
  {
      $name = $_POST['username'];
  
      //$password = password_hash($_POST['password'], PASSWORD_BCRYPT);
      $password = $_POST['password'];
      $name = mysql_real_escape_string($name);
      $password = mysql_real_escape_string($password);
  }
  
  function LOGIN($Name, $Password)
  {
      $conn = new mysqli(HOST,USER,PASSWORD,DATABASE);
  
      if ($conn-&gt;connect_errno) 
      {
          printf("Connect failed: %s\n", $conn-&gt;connect_error);
          exit();
      }   
  
      if ($result = $conn-&gt;query("SELECT * FROM persons WHERE Username='$Name'", MYSQLI_USE_RESULT))
      {
          printf("Select returned %d rows.\n", $result-&gt;num_rows);
          echo "&lt;br&gt;Name  Dump&lt;br&gt;";
          var_dump($Name);
          echo "&lt;br&gt;Password  Dump &lt;br&gt;"; 
          var_dump($Password);
          echo "&lt;br&gt;";
          echo "&lt;br&gt;";
          var_dump( $result);
          $result-&gt;close();
      }
      else
      {
          echo"no details returned &lt;br&gt;";
          var_dump( $result);
          $result-&gt;close();
      }
  }
  ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
  &lt;title&gt;Login&lt;/title&gt;
  &lt;link type="text/css" href="css.css" rel="stylesheet" /&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
  
  &lt;form action="login.php" method="post" name="login-form"&gt;
  Email: &lt;input type="text" name="username" /&gt;&lt;br&gt;
  Password: &lt;input type="password" name="password"/&gt;
  &lt;input type="submit" value="Login"/&gt;
  &lt;/form&gt;
  
  &lt;?php
  
  if ($_SERVER['REQUEST_METHOD'] == 'POST') 
  {
      LOGIN($NAME, $PASSWORD); 
  }
  
  ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>The result is</strong> </p>
  
  <pre><code>    Select returned 0 rows.
  This is what I have typed in username field: 
  This is what I have typed in password field:
  Name from DB:
  Password from DB:
  
  object(mysqli_result)#2 (5) { ["current_field"]=&gt; int(0) ["field_count"]=&gt; int(5) ["lengths"]=&gt; NULL ["num_rows"]=&gt; int(0) ["type"]=&gt; int(0) }
  </code></pre>
  
  <p>Any ideas where I am going wrong? <br />
  The column for my hash is Vchar(255) I gave it enough room from the beginning.</p>
  
  <p>Update! This maybe more serious, I have changed the code above to reflect the excellent answer from maytham. however it is still returning 0 results<br>
  I took the liberty of adding within the loop, <code>if (isset($_POST['username']))</code> </p>
  
  <pre><code>echo "This is what the value name is: ".$name."&lt;br&gt;";
  </code></pre>
  
  <p>and the same just before i call LOGIN($name, password); to see if $name is set, it is.<br>
  however between the function being called and $Name being used in the sql query the value is empty. Not sure why that would be I'll have to debug my php installation to see if there is any bugs.</p>