Fatal error on detail page

#1

Hello! I’ve been struggling with this for quite a while now! :-o
I have a php/mysqli “properties.php” page that has a url table link to a “properties_details.php” page and am getting a fatal error on the details page.

I am using a remote mysql database on a godaddy hosting account. I am running PHP 5.6 and the typical plugins are selected. The properties display in a web page fine and I see the record id number in the url when I click a link (street) on the properties page and go to the detail page for the record.

My error is this:

“Fatal error: Call to undefined method mysqli_stmt::get_result() in /home/c52vd4xwknzn/public_html/properties_details.php on line 46.”

I added “// LINE 46 DIRECTLY BELOW ----” right above line 46 to identify it.

Here is my php code on the “properties_details.php” page where the error is:

<?Php
  error_reporting(E_ALL);
  ini_set("display_errors", 1);

  // Collecting data from query string
  $id=$_GET['id'];

  // Checking data it is a number or not
  if(!is_numeric($id)){
  echo "Data Error";
  exit;
  }
  
  // MySQL connection string
  require "mysqli_connect.php";

  $count="SELECT * FROM properties where id=?";

  if($stmt = $dbc->prepare($count)){
    $stmt->bind_param('i',$id);
    $stmt->execute();

   // LINE 46 DIRECTLY BELOW ----

   $result=$stmt->get_result();
   echo "No of records : ".$result->num_rows."<br>";
   $row=$result->fetch_object();

  echo "<table>";
  echo "<tr ><td><b>Street</b></td><td>$row->street</td></tr>
  <tr><td><b>City</b></td><td>$row->city</td></tr>
  <tr><td><b>State</b></td><td>$row->state</td></tr>
  <tr><td><b>Rent</b></td><td>$row->rent_due</td></tr>
  <tr><td><b>Type</b></td><td>$row->type</td></tr>
  ";
  echo "</table>";
  }else{
  echo $dbc->error;
  }
  ?>

One the “properties_details.php” page, I expect to see all the listed fields for the one record that I selected on the “properties.php” page. Here is a link to the “properties.php” page:
http://cwdpreview.com/properties.php (there are 2 property records)

#3

The mysqli stmt get_result() method is only available if the mysqlnd driver is being used. If you don’t manage your own server, you cannot guarantee that it is and you should avoid using the get_result() method as it results in non-portable code.

Rather than to waste time rewriting your code to use the messy mysqli stmt bind_result() method, you should switch to the much simpler and more consistent php PDO database extension. It doesn’t have any problems like the one you are currently experiencing.

1 Like
#4

Thanks so much for your quick response! My CPanel has the following options for PHP versions:
7.3, 7.2, 7.1, 7.0, 5.6. Which version should I set it to? As you can see, I am just learning to use some PHP.

Also, this is my first post here. Was this an appropriate post here?

Thanks,
Mike

#5

as PHP 7.3 is stable you should use this.