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

0

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

  

error Notice: Trying to get property of non-object in C: \ wamp64 \ www \ sondplay \ admin \ process \ proc_edit_user.php on line 25

In my if I check if there was any change in the lines and if there was the message that the user was modified and redirected to page list users and otherwise displays the message that the user was not successfully edited the error I guess which is not 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>
    
asked by anonymous 27.03.2017 / 01:24

2 answers

3

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

Do not use

if ($count->rowCount > 0) {

Use

if ($count > 0)
    
27.03.2017 / 01:48
1

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

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

if ($del->rowCount() > 0) {
    
27.03.2017 / 01:30