1

I am working with the demo on https://www.tutorialrepublic.com/php-tutorial/php-mysql-crud-application.php. All the files work on my localhost; however, when I try to view or update a record I receive a 500 internal server error. I am hosted on godaddy.com using cpanel. I have tried changing the permissions of the php pages with no luck. Any help would be appreciated.

Thank you!

Error Log -

[19-Mar-2020 15:32:59 UTC] PHP Fatal error:  Uncaught Error: Call to undefined method mysqli_stmt::get_result() in /home/stqjgdx34a6w/public_html/demo/read.php:19
Stack trace:
#0 {main}
  thrown in /home/stqjgdx34a6w/public_html/demo/read.php on line 19

    <?php
// Check existence of id parameter before processing further
if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){
    // Include config file
    require_once "config.php";
    
    // Prepare a select statement
    $sql = "SELECT * FROM employees WHERE id = ?";
    
    if($stmt = $mysqli->prepare($sql)){
        // Bind variables to the prepared statement as parameters
        $stmt->bind_param("i", $param_id);
        
        // Set parameters
        $param_id = trim($_GET["id"]);
        
        // Attempt to execute the prepared statement
        if($stmt->execute()){
            $result = $stmt->get_result();
            
            if($result->num_rows == 1){
                /* Fetch result row as an associative array. Since the result set contains only one row, we don't need to use while loop */
                $row = $result->fetch_array(MYSQLI_ASSOC);
                
                // Retrieve individual field value
                $name = $row["name"];
                $address = $row["address"];
                $salary = $row["salary"];
            } else{
                // URL doesn't contain valid id parameter. Redirect to error page
                header("location: error.php");
                exit();
            }
            
        } else{
            echo "Oops! Something went wrong. Please try again later.";
        }
    }
     
    // Close statement
    $stmt->close();
    
    // Close connection
    $mysqli->close();
} else{
    // URL doesn't contain id parameter. Redirect to error page
    header("location: error.php");
    exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>View Record</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
    <style type="text/css">
        .wrapper{
            width: 500px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
    <div class="wrapper">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-12">
                    <div class="page-header">
                        <h1>View Record</h1>
                    </div>
                    <div class="form-group">
                        <label>Name</label>
                        <p class="form-control-static"><?php echo $row["name"]; ?></p>
                    </div>
                    <div class="form-group">
                        <label>Address</label>
                        <p class="form-control-static"><?php echo $row["address"]; ?></p>
                    </div>
                    <div class="form-group">
                        <label>Salary</label>
                        <p class="form-control-static"><?php echo $row["salary"]; ?></p>
                    </div>
                    <p><a href="index.php" class="btn btn-primary">Back</a></p>
                </div>
            </div>        
        </div>
    </div>
</body>
</html>
ciresuark
  • 71
  • 4
  • 1
    See in the log what kind of error you get – Igor Popov Mar 19 '20 at 16:00
  • 1
    500 Internal Server Error is a generic error message informing you that the server crashed while processing the request. Beyond that, it's meaningless, and is of very little use for debugging. You need to check the error logs on the server to try and find the underlying exception message. Once you've got that, you stand a chance of identifying the problem. – ADyson Mar 19 '20 at 16:01
  • 2
    Does this answer your question? [Call to undefined method mysqli\_stmt::get\_result](https://stackoverflow.com/questions/8321096/call-to-undefined-method-mysqli-stmtget-result) – rkok Mar 19 '20 at 19:59

1 Answers1

0

Mysqlnd driver needs to be enabled in order to use get_result(). You can use phpinfo() to check whether if it is enabled or not. If you are using cpanel, you can enable it in PHP extensions. If the error still occurs even after enabling the mysqlnd, uncheck the mysqli and check the nd_mysqli.

cpanel extension should look like this:

enter image description here

Boris Sokolov
  • 1,738
  • 4
  • 18
  • 30