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>