title: Query not working on login script
body: <p>At the moment I'm working on my first login script. In my script I'm trying to confirm if the username exists, if the user is active, what's the user's ID and if the username and password are matching or not. (See code below)</p>
  
  <pre><code>function sanitize($con, $data) {
  return mysqli_real_escape_string($con, $data);
  }
  
  function user_exists($username, $con) {
  $username = sanitize($con, $username);
  $query = mysqli_query($con, "SELECT COUNT(*) FROM users WHERE username='$username'") or die (mysqli_error());
  $result = mysqli_fetch_row($query);  
  return ($result[0] == 1) ? true : false;
  }
  
  function user_active($username, $con) {
  $username = sanitize($con, $username);
  $query = mysqli_query($con, "SELECT COUNT(*) FROM users WHERE username='$username' AND    active=1") or die (mysqli_error());
  $result = mysqli_fetch_row($query);  
  return ($result[0] == 1) ? true : false;
  }
  
  function user_id_from_username ($username, $con) {
  $username = sanitize($con, $username);
  $query = mysqli_query($con, "SELECT user_id FROM users WHERE username='$username'") or die (mysqli_error());
  $result = mysqli_fetch_row($query);  
  return $result[0];
  }
  
  function login($username, $password, $con) {
  $user_id = user_id_from_username($con, $username);
  $username = sanitize($con, $username);
  $password = md5($password);
  $query = mysqli_query($con, "SELECT COUNT(*) FROM users WHERE username='$username' AND   password='$password'") or die (mysqli_error());
  $result = mysqli_fetch_row($query); 
  return ($result[0] == 1) ? true : false; 
  }
  </code></pre>
  
  <p>I tried to confirm if the correct data was outputted by writing the code below.</p>
  
  <pre><code>if (user_exists('susievanveen', $con) === true) {
  echo 'user exists';
  }
  else {
  echo 'user doesn\'t exist';
  }
  
  if (user_active('susievanveen', $con) === true) {
  echo ' and user is active.';
  }
  
  else {
  echo ' and user is not active yet.&lt;br&gt;&lt;br&gt;';
  }
  
  echo 'User ID = ', user_id_from_username($username='susievanveen', $con);
  echo '&lt;br&gt;Active = ', user_active($username='susievanveen', $con);
  echo '&lt;br&gt;Match found between username and password = ', login($username='susievanveen', $password='password', $con);
  </code></pre>
  
  <p>I get the right results about the user existance,  whether the user is active or not and it's user ID. But it won't return any data about whether the username and password are matching or not. So can anybody tell me what's wrong with this code?</p>