title: How to create a database-driven user profile from logged-in user
body: <p>I'm currently trying to query based on my logged in user but i keep getting an error.</p>
  
  <p><strong><em>This is my homepageDemo.php</em></strong></p>
  
  <pre><code>&lt;?php
  //including the database connection file
  include 'config.php';
  
  $_SESSION['userID']= $rows['userID'];
  
  //fetching data in descending order (lastest entry first)
  //$result = mysql_query("SELECT * FROM users ORDER BY id DESC"); // mysql_query is deprecated
  $result = mysqli_query($mysqli, "SELECT m.moduleID, m.moduleName
  FROM modules m
  JOIN courses c ON m.courseID = c.courseID
  JOIN usersDemo u ON c.courseID = u.courseID
  WHERE userID = '$userID'"); // using mysqli_query instead
  
  
          //while($res = mysql_fetch_array($result)) { // mysql_fetch_array is deprecated, we need to use mysqli_fetch_array 
          while($res = mysqli_fetch_array($result)) {     
              echo "&lt;tr&gt;";
              echo "&lt;td&gt;"."&lt;a&gt;".$res['moduleID']."&lt;/a&gt;"."&lt;/td&gt;";
              echo "&lt;td&gt;"."&lt;a&gt;".$res['moduleName']."&lt;/a&gt;"."&lt;/td&gt;";
          }
          ?&gt;
  </code></pre>
  
  <p><strong><em>This is my accounts/login.php</em></strong></p>
  
  <pre><code>&lt;?php 
    session_start();
  
    include '../inc/db.php';
    include '../inc/functions.php';
    $json = [];
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
      $email = p_s($_POST['email']);
      $password = p_s($_POST['password']);
  
  
      /* ==============================================
      Data not empty
      ================================================*/
      if (!empty($email) &amp;&amp; !empty($password)) {
        /* ==============================================
        first make sure if the email exist or not 
        ================================================*/
        if (checkIfEmailExist($email)) {
  
          /* ==============================================
          Check Password
          ================================================*/
          if (checkPassword($email, $password)) {
  
                  $sql = "SELECT * FROM usersDemo WHERE email = '$email'";
                  $run = mysqli_query($conn,$sql);
                  while ($rows = mysqli_fetch_assoc($run)) {
                      $_SESSION['userID']= $rows['userID'];
                      $_SESSION['fName']= $rows['fName'];
                      $_SESSION['lName']= $rows['lName'];
                      $_SESSION['email']= $rows['email'];
                      $_SESSION['courseID']= $rows['courseID'];
                      $_SESSION['lastactive']= $rows['lastactive'];
                      header('Location: ../homepageDEMO.php?logged');exit();
                  }
  
          }else{
              header('Location: ../signup.php?er1');exit();
          }
        }else{
          header('Location: ../signup.php?er2');exit();
        }
      }else{
          header('Location: ../signup.php?er3');exit();
      }
  
  
    }
  </code></pre>
  
  <p><strong><em>These are my functions that contain my login validation</em></strong></p>
  
  <pre><code>function checkIfEmailExist($email){
    global $conn;
    $data[]=array();
    $sql = "SELECT userID FROM usersDemo WHERE email ='$email'";
    $run = mysqli_query($conn, $sql);
    $rows =mysqli_num_rows($run);
    if ($rows == 0) {
      return false;
    }else{
      return true;
    }
  }
  function checkPassword($email, $password){
    global $conn;
    $sql = "SELECT password FROM usersDemo WHERE email ='$email'";
    $run = mysqli_query($conn, $sql);
    while ($rows = mysqli_fetch_assoc($run)) {
      $hashedDBPass = $rows['password'];
    }
    if (password_verify($password, $hashedDBPass)) {
      return true;
    }else{
      return false;
    }
  }
  </code></pre>
  
  <p><strong><em>and this is my database structure that contains the tables in question</em></strong></p>
  
  <p><a href="https://i.stack.imgur.com/ACvRA.png" rel="nofollow noreferrer">Database Structure</a></p>
  
  <p>Would anyone be able to assist me in where i'm going wrong?</p>
  
  <p>Thanks in advance.</p>