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();
}
?>