0

Am trying to log into the client account and validate the info using validate.php but give gives the below error .I have registred 4 employees already as admin.

<?php
session_start();
include 'connect.php';
require 'update_leaves.php';
$username = strip_tags(trim($_POST['uname']));
$password = strip_tags(trim($_POST['pass']));

$sql = "SELECT UserName, EmpPass,UpdateStatus,Dept FROM employees";
$result = $conn->query($sql);
if($result->num_rows>0){
    while($row = $result->fetch_assoc()) {
        if(($username == $row["UserName"]) && ($password == $row["EmpPass"])) {
            $_SESSION["user"] = $username;
            $dept = $row["Dept"];
            $status = update_leaves($username,$dept);
            if($status  === true) {
                header('location:home.php?msg='.urlencode('Your Leaves Were Updated Successfully !'));
                exit();
            } else
                header('location:home.php');
        } else {
            header('location:index.php?err='.urlencode('Username Or Password Incorrect'));
            exit();
        }
    }
} else {
    echo "Database Empty ! Please register some employees first";
}   
?>

Notice: Trying to get property 'num_rows' of non-object in C:\xampp\htdocs\leave\client\validate.php on line 10 Database Empty ! Please register some employees first

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • 2
    There is an error in your mysql query. You have to learn which one through mysqli error reporting. Besides, almost everything else in this code is wrong. You need to get yourself a decent tutorial. Here is a minimal essential code for checking a login and password using mysqli: https://phpdelusions.net/mysqli/password_hash – Your Common Sense Mar 12 '20 at 12:45
  • It's really inefficient to select all the rows and then loop through them to find a matching one. SQL does this far better and more efficiently by use of the `WHERE` clause in the SQL statement - see https://www.tutorialspoint.com/sql/sql-where-clause.htm (and many others for examples). And the above comment is correct, there is a lot else wrong with this code, too. – ADyson Mar 12 '20 at 13:38

0 Answers0