I'm currently trying to query based on my logged in user but i keep getting an error.
This is my homepageDemo.php
<?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 "<tr>";
echo "<td>"."<a>".$res['moduleID']."</a>"."</td>";
echo "<td>"."<a>".$res['moduleName']."</a>"."</td>";
}
?>
This is my accounts/login.php
<?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) && !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();
}
}
These are my functions that contain my login validation
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;
}
}
and this is my database structure that contains the tables in question
Would anyone be able to assist me in where i'm going wrong?
Thanks in advance.