Sunday, 25 August 2013

Object of class mysqli_result could not be converted to int

Object of class mysqli_result could not be converted to int

i'm trying to create a php countdown for my automated watering, i'm going
to have crontab run this every minute and turn of the watering
automatically. the code is as follows
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include 'php_serial.class.php';
require_once 'login.php';
//connect to server
$con = mysqli_connect($server,$username,$password);
if(!$con){
die("Failed to connect:" . mysqli_connect_error());
}
else {
//check database connection
$open_db = mysqli_select_db($con,$db);
if(!$open_db){
die("Cannot connect to vatten database" . mysqli_error());
}
}
//check time_left
$sql = "SELECT time_left FROM `info`";
$time_left = mysqli_query($con,$sql);
$sql2 = "SELECT last_sent FROM `info`";
$last_sent = mysqli_query($con,$sql2);
if(!$time_left) {
die("Database access failed" . mysqli_error($con));
}
if($time_left >0) { // Error 1 here
$time_left = $time_left-1; // Error 2 here
mysqli_query($con, "UPDATE info SET time_left=$time_left");
}
elseif($time_left <1 && $last_sent !== "[LOOOOOO]") {
$serial = new phpSerial;
$serial->deviceSet("/dev/ttyUSB0");
$serial->confBaudRate(1200);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->deviceOpen();
$serial->sendMessage("[LOOOOOO]");
mysqli_query($con, "UPDATE info SET time_left=$time_left");
}
mysqli_close($con);
?>
So the error i'm getting is Notice: Object of class mysqli_result could
not be converted to int in /var/www/vatten/check.php on line 27
and another one like that but for line 28.
And apart from that it resets the "time_left" in the database to 0
Any help would be appreciated!

No comments:

Post a Comment