0

I know there are other people with this error message. But there is not the answer i need. It keeps giving me the error.. I really need to fix this. This is my code:

<?php

if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['submit']))
{
$DBConnect = mysqli_connect("localhost", "root", "");
$email = mysqli_real_escape_string($DBConnect, $_POST['email']);
$wachtwoord = mysqli_real_escape_string($DBConnect, $_POST['wachtwoord']);

if(!empty($email) && !empty($wachtwoord))
{
    $selectGebruiker = mysqli_query($DBConnect, "SELECT lidID, wachtwoord FROM geregistreerden WHERE email='$email'");

    while ($row = $selectGebruiker->fetch_assoc())
    {
        $email = $row['email'];
        $wachtwoordHash = $row['wachtwoord'];
    }

    $checkGebruiker = mysqli_num_rows($selectGebruiker);

    $wachtwoordCheck = password_verify ( $wachtwoord , $wachtwoordHash );

    if( $checkGebruiker && $wachtwoordCheck )
    {
        $_SESSION['email'] = $email;
        echo "gelukt!!";
    }
    else
    {
        $loginError = 'Email / wachtwoord is onjuist';
        echo "Onjuist";
    }

}
else
{
    $loginError = 'Email / wachtwoord is onjuist.';
}
}
?>
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    Mixing `Object oriented style` with `Procedural style` just use `while ($row = mysqli_fetch_assoc($selectGebruiker)) {` – Saty Jan 08 '16 at 10:22
  • Because $selectGebruiker is returning a boolean value, probably 0. – Yuri Blanc Jan 08 '16 at 10:22
  • mysqli_query returning 0 (false) because of given error, imo because of not database selected (put a 4th param in mysqli_connect) – Reloecc Jan 08 '16 at 10:23
  • Before going into `while loop` use `mysqli_num_rows()` to check weather your query return rows or not!! – Saty Jan 08 '16 at 10:26

1 Answers1

2

Check the query you're running with mysqli_query.

While on successful query it returns the result object, on failure it returns a boolean FALSE, that's why you're getting the error.

You can find more info in the docs: http://php.net/manual/en/mysqli.query.php

jedrzej.kurylo
  • 39,591
  • 9
  • 98
  • 107
  • Beat me too it! The solution is to output the query - run in it on the database directly and see what error comes back. – Ukuser32 Jan 08 '16 at 10:25