5

I keep getting the error PHP Fatal error: Call to undefined function mysqli_stmt_get_result(). I am using PHP version 5.6 and have enabled the extension mysqlind in my hosting provider c panel but I can't figure out why I am still getting this error. I have researched and found every time that I need to have mysqli nd enabled to use mysqli_stmt_get_result. Can anyone assist/teach what I am doing wrong. Thank you.

SIGNUP.PHP:

<?php
    session_start();
    include '../dbh.php';

    $respond = array(
        'status' => true,
        'message' => 'There was an error',
        'redirect',
        'errors'
    );

    if (isset($_POST['submit'])) {

        $first = $_POST['first'];
        $last  = $_POST['last'];
        $email = $_POST['email'];
        $pwd   = $_POST['pwd'];

        $errorEmpty = false;
        $errorEmail = false;


        if (empty($first) || empty($last) || empty($email) || empty($pwd)) {

            $respond['errors'][]   = "Please fill out all fields!";
            $respond['errorEmpty'] = true;

        } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            $respond['errors'][]   = "Please enter a valid email address!";
            $respond['errorEmail'] = true;

        } else {
            $sql  = "SELECT email FROM user WHERE email= ? ";
            $stmt = mysqli_prepare($conn, $sql);
            mysqli_stmt_bind_param($stmt, 's', $email);
            mysqli_stmt_execute($stmt);
            $result   = mysqli_stmt_get_result($stmt);  //This is where I getting my error
            $num_rows = mysqli_num_rows($result);
            if ($num_rows > 0) {
                $respond['errors'][]   = "That email address already exists!";
                $respond['errorEmail'] = true;
            }

            else {
                $encryptpwd = password_hash($pwd, PASSWORD_DEFAULT);
                $sql        = "INSERT INTO user (first, last, email, pwd) VALUES (?,?,?,?)";
                $stmt       = mysqli_prepare($conn, $sql);
                mysqli_stmt_bind_param($stmt, 'ssss', $first, $last, $email, $password_hash);

                if (mysqli_stmt_execute($stmt)) {

                    $userID = mysqli_insert_id($conn);
                    $status = 1;
                    $sql2   = "INSERT INTO profileImg (email, status) VALUES(?,?)";
                    $stmt2  = mysqli_prepare($conn, $sql2);
                    mysqli_stmt_bind_param($stmt2, 'si', $email);
                    mysqli_stmt_execute($stmt);

                    $_SESSION['id'] = $userID;

                    $respond['redirect'] = "../profile.php?id=$userID";
                }
            }
        }
    }
    echo json_encode($respond);
    ?>

5 Answers5

6

To prevent others from hours of screaming trying to figure out why this does not work when you have the mysqlnd native driver enabled. It is because you need to make sure you enable both native drives. Both mysqlnd and nd_mysqli need to be enabled on your server if you wish to use this functionality.

Otherwise just enabling the mysqlnd native driver does not include the mysqli_stmt_get_result function as this apparently resides in the nd_mysqli native driver. Unfortunately, most documentation only ever talks about the mysqlnd native driver.

Once you enable both native drivers this function works as documented.

Oh and on my hosting server you need to disable/uncheck mysqli to enable nd_mysqli.

Screenshot of cpanel

Jérémie Bertrand
  • 2,917
  • 3
  • 41
  • 48
Jeff
  • 67
  • 1
  • 5
1

Do you have the mysqlnd driver properly installed? Per a comment in the Manual:

If you don't have mysqlnd installed/loaded whatever, you will get an undefined reference when trying to call "mysqli_stmt_get_result()".

Also, there are discussions about this issue here and here.

Lastly, here's a forum discussing info pertaining to using the driver with cpanel that you may find useful.

slevy1
  • 3,623
  • 2
  • 23
  • 30
1

I had the same issue ("PHP Fatal error: Call to undefined function mysqli_stmt_get_result()")and all it took was to change the version of php the server was auto set too ie 5.6 to 7.2, and to make sure the nd_mysqli is checked. Note that mysqlnd is contraindicated in the place of nd-mysqli.

Steps:
Find the change php version section in cpanel
Choose highest version of php at current 7.2
Ensure nd_mysqli is checked from list of extensions
In case of any error try un-checking mysqlnd

Emmanuel Neni
  • 155
  • 1
  • 10
1

Your are using procedural way of Getting Data.

If possible you may use object oriented way so not need to enable nd_mysqli on server.

$sql = "SELECT * FROM users WHERE id=?"; // SQL with parameters
$stmt = $conn->prepare($sql); 
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result(); // get the mysqli result
$user = $result->fetch_assoc(); // fetch data 
Vivek Pawar
  • 191
  • 1
  • 5
0

Just check your database table name on your server if it match on your php code. On the right side of your server sql admin you can find this links. Click the "create php code" then use the exact table name shown like this:
$sql = "SELECT * FROM 'users' WHERE id=?"; links image On my part the code looks like this: table name image $sql = "SELECT * FROM 'pending_products' WHERE id=?";

Dharman
  • 21,838
  • 18
  • 57
  • 107
Humanoid
  • 47
  • 6