Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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);
    ?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...