PHP, MYSQL -Trying to get property of non-object

0

Good evening!

I have an error with a query in Mysql, and I'm going around and I do not see it, to see if you can help me.

The error is:

  

Trying to get property of non-object

I know the error comes from the query.

I've tried with:

$comp2 = mysqli_query($conexion,"UPDATE enlace SET enlace.dias = '".$d."' WHERE NEntrega = '".$num."' ");

also with:

$comp2 = mysqli_query($conexion,"UPDATE enlace SET enlace.dias = '".$d."' WHERE NEntrega = '".$num."' and NRecogida = '".$a_comp['NRecogida']."' ");

also with:

$comp2 = mysqli_query($conexion,"UPDATE enlace SET enlace.dias = '0' WHERE NEntrega = '".$num."' ");

and with:

$comp2 = mysqli_query($conexion,"UPDATE enlace SET enlace.dias = 0 WHERE NEntrega = '".$num."' ");

But no option works.

Things to keep in mind is that: $d = '0' (I've also tried with $d = 0 and nothing)

which link has two external keys that are also its primary keys called NEntrega and NRecogida , plus it has a column days of type int.

a_comp['NRecogida'] is from a previous query that goes well.

and $num is a parameter that we pass to the function.

Thanks in advance.

The complete code is:

function Pagar($conexion,$num){
    $res = mysqli_query($conexion,"SELECT * FROM albaran WHERE NumAlbaran = '".$num."' ");
    if($res->num_rows > 0){
        $daux = new DateTime('NOW');
        $daux2 = $daux->format('Y-m-d');
        $res2 = mysqli_query($conexion,"UPDATE albaran SET fecha_pagado = '".$daux2."' WHERE NumAlbaran = '".$num."' ");
        if(!$res2){
            echo "<tr><td><div class='alert alert-danger'>
                <strong> No se ha podido pagar. </strong>
            </div></td></tr>";
        }
        else{
            $comp = mysqli_query($conexion,"SELECT * FROM enlace WHERE NEntrega = '".$num."' ");
            //pagamos uno que ya hemos recogido y se pasó de dias
            if($comp->num_rows > 0){
                $d = 0;
                $a_comp =  mysqli_fetch_assoc($comp);
                $comp2 = mysqli_query($conexion,"UPDATE enlace SET enlace.dias = '".$d."' WHERE NEntrega = '".$num."' ");
                echo $comp2;
                if($comp2 && ($comp2->num_rows > 0)){
                    echo "<tr><td><div class='alert alert-success'>
                        <strong> PAGADO </strong>
                    </div></td></tr>";
                }
                else{
                    echo "<tr><td><div class='alert alert-danger'>
                        <strong> No se ha podido pagar bien. </strong>
                    </div></td></tr>";
                }
            }
            else{
                //no tenia enlace pero ha pagado
                echo "<tr><td><div class='alert alert-success'>
                    <strong> PAGADO </strong>
                </div></td></tr>";
            }

        }

    }
    else{
        echo "<tr><td><div class='alert alert-danger'>
            <strong> No se ha podido pagar. </strong>
        </div></td></tr>";
    }
    unset($_POST['Pay']);
    unset($_POST['NumPay']);
}
    
asked by Monetillo 19.09.2018 в 22:56
source

0 answers