title: How store user ID as session in login.php
body: <p>I have the following functions in a file called user.php:</p>
  
  <pre><code>        function user_id_from_username($username) {
              $username = sanitize($username);
              return mysql_result(mysql_query("SELECT `MemberID` FROM `member` WHERE `Email` = '$username'"),0, 'MemberID');
  
              }
          function login ($username, $password) {
              $MemberID = user_id_from_username ($username);
  
              $username = sanitize($username);
              $password = md5($password);
  
              return (mysql_result(mysql_query("SELECT COUNT(`MemberID`) FROM `member` WHERE `Email` = '$username' AND `Password` ='$password'"), 0) == 1) ? $MemberID : false; }
  </code></pre>
  
  <p>And in my login.php I have:</p>
  
  <pre><code>Session_start ();
  include 'core/functions/users.php'
  
  if (empty($_POST) === false){
      $username = $_POST['Email'];
      $password = $_POST['Password'];
  
  
          $login = login($username, $password);
          if($login === 1){
              $_SESSION['MemberID'] = $login; //logged in and returned user ID and store in session
              header('location: member.php?username='.$username);
  
          }else{
              // try admin login
              $query2 = mysql_query("SELECT * FROM admin WHERE Email ='$username' AND Password ='$password'");
              if(mysql_num_rows($query2) == 1){
                  $_SESSION['Email'] = $username;
                  header("location: admin.php");
              }
              else{
                   echo "Failed Login Attempt"; 
  
              }
          }
      }
  </code></pre>
  
  <p>When I try to log a user in I get this error:</p>
  
  <p>Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 8 in oddjobexchange\core\functions\user.php on line 27
  Failed Login Attempt</p>
  
  <p>I can't get my head around this error because I can't see anything wrong with line 27 (below)</p>
  
  <pre><code>return mysql_result(mysql_query("SELECT `MemberID` FROM `member` WHERE `Email` = '$username'"),0, 'MemberID');
  </code></pre>
  
  <p>In my DB 'MemberID' is row 0, 'Email' is row 7 and 'Password' is row 8. Anybody know what I've got wrong?</p>