-1

I keep trying to find out how to fix this in my login system but it keeps failing at $result, trying to convert it into an array causes my login to fail.

    if (isset($_POST['log'])) {
        $username = mysqli_real_escape_string($dbcon, $_POST['username']);
        $password = mysqli_real_escape_string($dbcon, $_POST['password']);
        $sql = "SELECT * FROM admin WHERE username = '$username'";
        $result = mysqli_query($dbcon, $sql);
        $rows = mysqli_num_rows($result);
        if ($rows == 1 && password_verify($password, $result['password'])) {
            $_SESSION['username'] = $username;
            header("location: admin.php");
        } else {
            echo "Incorrect details!";
        }
    }
Vega
  • 27,856
  • 27
  • 95
  • 103
Vuzeo
  • 7
  • 4
  • You must stop using `mysqli_real_escape_string`. It will cause you bugs in your code. Just use prepared statements like everyone else – Dharman Aug 13 '21 at 12:21
  • Please do not put answer parts in the question post – Vega Aug 14 '21 at 11:41

1 Answers1

0

You are trying to count the result without fetching them. Try below:

Change

$result = mysqli_query($dbcon, $sql);

to

$result = mysqli_fetch_all(mysqli_query($dbcon, $sql), MYSQLI_ASSOC);