I'm trying to do a query on mysql in php, but I get an error on line 131, which is:
$num = $res->num_rows;
The error is:
Trying to get property of non-object.
I know that the error comes from the query but I can not find it. Could you help me please?
This is the code:
function Enlazar($conexion,$NumAlbaran,$cont,$empCont,$fecha2){
$conseguido = true;
//buscamos su entrega
//mala sentencia sql
$ocup = 'ocupado';
$ent = 'Entrega';
$res = mysqli_query($conexion,"SELECT albaran.NumAlbaran,albaran.fecha,albaran.fecha_pagado FROM albaran,contenedor,solicita WHERE contenedor.estado = '".$ocup."' and numCont = '".$cont."' and solicita.empresa = '".$empCont."' and albaran.tipo='".$ent."' ");
$num = $res->num_rows;
echo $num;
if($num == 1 ){
$a_res = mysqli_fetch_assoc($res);
$intervalo = CalcularIntervalo2($a_res['fecha'],$a_res['fecha_pagado'],$fecha2);
//vinculamos la entrega con su recogida/residuo
$aux = $a_res['NumAlbaran'];
$res2 = mysqli_query($conexion,"INSERT INTO enlace (NEntrega,NRecogida,dias) VALUES ($aux,'$NumAlbaran','$intevalo') ");
if(!$res2){
$conseguido = false;
}
}
else{
$conseguido = false;
}
return $conseguido;
}
The albaran table has the fields: NumAlbaran, nomEmp, location, date, type and date_paid.
The table you request, with which you link the delivery notes with the containers, has the fields: numAlbaran, numCont, company.
The container table has: numCont, company, size, state.