title: PHP MySQL login function
body: <p>I'm using this:</p>
  
  <pre><code>function authUser($username, $password){
      connectDB();
      $sql = "SELECT id, username FROM users where username = '".$username."' and password = '".$password."'";
      $result = mysql_query($sql);
      $num_rows = mysql_num_rows($result);
      if ($num_rows &gt; 0){
          while ($row = mysql_fetch_array($result)){
              $username = $row['username'];
              session_start(); 
              session_register('username');
          return $username; 
          }
      }
      closeConn();
  }
  </code></pre>
  
  <p>With a combination of this:</p>
  
  <pre><code>$auth = authUser($username, $password);
  if (isset($username)){
      header( "Location: index.php" );
  }
  </code></pre>
  
  <p>And then on the index.php (where i redirect them if a successful login) i'm trying to echo $username. But nothing is showing? Any ideas? Is this function the problem?</p>
  
  <p>EDIT:</p>
  
  <p>have now changed it so:</p>
  
  <pre><code>if ($num_rows &gt; 0){
      while ($row = mysql_fetch_array($result)){
          $_SESSION['username'] = $row['username'];
        return true; 
      }
  }
  </code></pre>
  
  <p>Is that right?</p>