title: Will not return MYSQLI Results for username
body: <p>I am trying to return a username when a user forgets their username.  I have it validating again their email address but for some reason it just keeps saying 'Error: cannot find username'. I am using the correct mysqli syntax I hope.  </p>
  
  <pre><code>if (isset($_POST['user'])) {
      $email = mysqli_real_escape_string($con, $_POST['email']);
      $username = "";
      if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
          $errmsg = 'Error: ' . $email . ' is not a valid email address';
      } else {
          $query = "SELECT email FROM admin WHERE email = '$email'";
          $results = mysqli_query($con, $query);
  
          $query2 = mysqli_fetch_array($results);
  
          if ($query2 == 0) {
              $errmsg = 'Error: ' . $email . ' is not found, please try again';
          }
          if (!errmsg) {
              $getuname = "SELECT * FROM admin WHERE email = '$email'";
              if (!mysqli_query($con, $getuname)) {
                  die('Error: ' . mysqli_error($con));
              }
              $row = mysql_fetch_array($getuname);
          }
          $username = '&lt;div class="registersuccess"&gt;Your username is: ' . $row['username'] . '&lt;/div&gt;';
      }
      $username = '&lt;div class="registererror"&gt;Error: cannot find username&lt;/div&gt;';
  
      mysqli_close($con);
  }
  </code></pre>
  
  <p>I am a noob when it comes to this but am pretty sure this is correct.  if not where did i go wrong?</p>