I'm having a very difficult time trying to figure out why this code is returning this error:
Call to undefined function mysqli_stmt_get_result() in _____ on line 46
This code is running fine on my local machine using XAMPP, but it's not when I upload it to my webhost. On my webhost I am running PHP Version 5.5.38 and on my local machine I am running PHP Version 5.6.34. Any advice? I've tried to look at other threads here on SO to figure out what's wrong, but I haven't had much luck so far. I have the mysqlnd driver ...
The line in question is the one directly under the error checks that reads as follows:
$result = mysqli_stmt_get_result($stmt);
<?php
ini_set('display_errors', '1');error_reporting(E_ALL);
session_start();
if(isset($_POST['submit'])){
include 'dbh.inc.php';
$username = mysqli_real_escape_string($conn, $_POST['username']);
$pass = mysqli_real_escape_string($conn, $_POST['password']);
if(empty($username) || empty($pass)){
header('Location:../login.php?login=empty');
exit();
} else {
$sql = "SELECT * FROM users WHERE username = ?";
$stmt = mysqli_stmt_init($conn);
if (mysqli_stmt_prepare($stmt, $sql) === false) {
trigger_error("Prep Error: " . mysqli_error($conn));
}
if (mysqli_stmt_bind_param($stmt, "s", $username) === false) {
trigger_error("Bind Error: " . mysqli_stmt_error($stmt));
}
if (mysqli_stmt_execute($stmt) === false) {
trigger_error("Execute Error: " . mysqli_stmt_error($stmt));
}
$result = mysqli_stmt_get_result($stmt);
$rows = mysqli_fetch_all($result, MYSQLI_ASSOC);
$num_rows = count($rows);
if($num_rows < 1){
header('Location:../login.php?login=error');
exit();
} else {
foreach ($rows as $row) {
$hashedPwdCheck = password_verify($pass, $row['user_pass']);
if($hashedPwdCheck == false){
header('Location:../login.php?login=ipass');
exit();
} elseif ($hashedPwdCheck == true) {
session_regenerate_id(true);
$_SESSION['user_id'] = $row['user_id'];
$_SESSION['username'] = $row['username'];
$_SESSION['first_name'] = $row['user_first'];
$_SESSION['last_name'] = $row['user_last'];
$_SESSION['user_email'] = $row['user_email'];
header('Location:../index.php?login=success');
exit();
}
}
}
}
} else {
header('Location:../index.php?login=error');
exit();
}