title: Beginner Help: PHP MySQL (PDO) Function
body: <p>I am trying to learn PHP and setup a user access based website. I finally found a template that is mostly simple to use and implement. However after hours of struggling to modify the template I have to kindly ask for assistance.</p>
  
  <p>The following code works great and I have modified the original template to be able to login using the email address as username and the stored password from the database. The original template were based on a username login instead of using the email address. What I am trying to achieve now is to somehow also include the field "username" from the same database and table and store it as a $username parameter to use elsewhere on the site, for example with "echo". I would like to still use the field but for the name of the registered member, rather than a username for login.</p>
  
  <p>I'm sure there is an easy way but whatever I change I keep getting error messages and I simply seem to not understand the syntax just yet.</p>
  
  <pre><code>&lt;?php
  include('password.php');
  class User extends Password{
  private $_db;
  function __construct($db){
      parent::__construct();
  
      $this-&gt;_db = $db;
  }
  private function get_user_hash($email){ 
      try {
          $stmt = $this-&gt;_db-&gt;prepare('SELECT password FROM members WHERE email = :email AND active="Yes"');
          $stmt-&gt;execute(array('email' =&gt; $email));
          $row = $stmt-&gt;fetch();
          return $row['password'];
  
      } catch(PDOException $e) {
          echo '&lt;p class="bg-danger"&gt;'.$e-&gt;getMessage().'&lt;/p&gt;';
      }
  }
  
  public function login($email,$password){
      $hashed = $this-&gt;get_user_hash($email);
  
      if($this-&gt;password_verify($password,$hashed) == 1){
  
          $_SESSION['loggedin'] = true;
          return true;
      }   
  }
  
  public function logout(){
      session_destroy();
  }
  public function is_logged_in(){
      if(isset($_SESSION['loggedin']) &amp;&amp; $_SESSION['loggedin'] == true){
          return true;
          }       
      }
  
  }
  ?&gt;
  </code></pre>