0

I am trying to display a result which will show the sum of all of the rent paid over a given time span. However I am getting the error "Recoverable fatal error: Object of class mysqli_result could not be converted to string"

Is there a way I can display this data using PHP?

Here is my code below:

<?php
ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

  $dateto = filter_input(INPUT_POST, 'dateto');
  $datefrom = filter_input(INPUT_POST, 'datefrom');


  if(!empty($dateto)){
if(!empty($datefrom)){
$host = "";
$dbusername = "";
$dbpassword = "";
$dbname = "some_db";

//new connection
$conn = new mysqli ($host, $dbusername, $dbpassword, $dbname);

if(mysqli_connect_error()){
  die('Connect Error ('. mysqli_connect_errno().')'
  . mysqli_connect_error());
}
else{
  $sql = "SELECT SUM(rentpm) FROM tenants";

  $result = $conn->query($sql);



  if ($conn->query($sql)){
    echo $result;

  }
  else{
    echo "Error: " . $sql ."<br>".$conn->error;
  }
  $conn->close();
}

}
else{
  echo "All fields are required!";
  die();
}
  }
  else{
    echo "Please fill out all fields to continue.";
    die();
  }
?>
canjess
  • 11
  • 4
  • Lot's of examples http://php.net/manual/en/mysqli.examples-basic.php – AbraCadaver Apr 16 '18 at 18:02
  • Also, unrelated, you run this query twice. Once to set the $result, then again to test... if it ran? It's a little odd. `if ($result = $mysqli->query($sql))` would be cleaner. [Check out the documentation for some examples](http://php.net/manual/en/mysqli.query.php) – JNevill Apr 16 '18 at 18:04

0 Answers0