0

My code code returns the error on line 5:

Fatal error: Call to undefined method mysqli_stmt::get_result()

$email = $_POST['email'];
$stmt = $con->prepare("SELECT password FROM users WHERE email=?");
$stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result();
$num_of_rows = $stmt->num_rows;

if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $password = $row['password'];
        $verify = password_verify($_POST['password'], $password);
        if ($verify) {
            echo "success";
        }
        else {
            echo "not success";
        }
    }
}

else {
    echo "incorrect username or password";
}

I'm running PHP 5.6 and mysqlnd is enabled.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Sebastian
  • 3,548
  • 18
  • 60
  • 95
  • `$num_of_rows = $stmt->num_rows; if ($result->num_rows` that is an issue here. Just use `if ($num_of_rows > 0)`. You're using the same method twice. – Funk Forty Niner Jan 24 '18 at 18:30
  • 1
    Are you absolutely positive mysqlnd is installed? https://stackoverflow.com/a/8343970/2960971 – IncredibleHat Jan 24 '18 at 18:32
  • if you're working local here and made any changes to system files, make sure you restarted. – Funk Forty Niner Jan 24 '18 at 18:33
  • @FunkFortyNiner argh, sorry hybrid code! What would I need to change this line to? `while ($row = $result->fetch_assoc()) {` – Sebastian Jan 24 '18 at 18:35
  • I myself never used `get_result()` but have a look at one of my answers that checks if a row exists https://stackoverflow.com/a/22253579/ maybe that would be of help, but it doesn't contain the `get_result()` method though. – Funk Forty Niner Jan 24 '18 at 18:36

0 Answers0