How do I resolve the "Notice: Trying to get Property of non-object in" error?

Asked

Viewed 29,285 times

1

I have an administrative panel and in the page to edit the user I receive the data by the form and do the update in the table so that always returns the message from

Notice error: Trying to get Property of non-object in C: wamp64 www sondplay admin processa proc_edit_usuario.php on line 25

in my if i check if there has been any change in the lines and if there is displays the message that the user has been modified and redirects to the user list page and otherwise displays the message that the user has not successfully edited the error think this in the rowCount my code

<?php
session_start();
include_once("../seguranca.php");
include_once("../conexao.php");
$id = $_POST["id"];
$nome = $_POST["nome"];
$email = $_POST["email"];
$usuario = $_POST["usuario"];
$senha = $_POST["senha"];
$nivel_de_acesso = $_POST["nivel_de_acesso"];

/* Delete all rows from the FRUIT table */
$del = $pdo->prepare("UPDATE usuarios set nome ='$nome', email = '$email', login = '$usuario', senha = '$senha', nivel_acesso_id = '$nivel_de_acesso', modified = NOW() WHERE id='$id'");
$del->execute();
$count = $del->rowCount();
?>
<!DOCTYPE html>
<html lang="pt-br">
    <head>
        <meta charset="utf-8">
    </head>

    <body>
        <?php
        if ($count->rowCount > 0) {
            echo "
                <META HTTP-EQUIV=REFRESH CONTENT = '0;URL=../administrativo.php?link=2'>
                <script type=\"text/javascript\">
                    alert(\"Usuário editado com Sucesso.\");
                </script>
            ";
        } else {
            echo "

                <script type=\"text/javascript\">
                    alert(\"Usuário não foi editado com Sucesso.\");
                </script>
            ";
        }
        ?>
    </body>
</html>

2 answers

5


The variable $count is an integer type value, not an object for you to call $count->rowCount.

Do not use

if ($count->rowCount > 0) {

Use

if ($count > 0)
  • now I understood gave straight thanks for the help

1

Try calling $del->rowCount in if, instead of assigning to a variable, the error is in this.

$count = $del->rowCount();// tirei isto

if ($del->rowCount() > 0) {
  • I did it the way I said and continues with the same message

  • Gives error in which line ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.