title: MySQLi Object-oriented redirect depending on user role
body: <p>Can't figure out where my error is, I want to redirect to different sections of the website depending on the user role.</p>
  
  <pre class="lang-php prettyprint-override"><code>if (isset($_POST['submit'])) {
      $stmt = $conn-&gt;prepare('SELECT id, password FROM accounts WHERE email = ?');
      $stmt-&gt;bind_param('s', $_POST['email']);
      $stmt-&gt;execute();
      $stmt-&gt;store_result();
  
      if ($stmt-&gt;num_rows &gt; 0) {
          $stmt-&gt;bind_result($id, $password);
          $stmt-&gt;fetch();
  
          if (password_verify($_POST['password'], $password)) {       
              session_regenerate_id();
              $_SESSION['loggedin'] = TRUE;
              $row = $result-&gt;fetch_assoc();
  
              if ($row['role']=='admin') {
                  header('Location: admin.php');
              } else if ($row['role']=='user') {
                  header('Location: profile.php');
              }
          } else {
              $password_incorrect = '¡Contraseña incorrecta! Si has olvidado tu contraseña puedes &lt;a href="#"&gt;restablecerla&lt;/a&gt;.';
          }
      }
  </code></pre>