Error in php search system

Asked

Viewed 58 times

0

I’m making a search system, only it’s giving an error, I’d like to know the solution.

Follows the code:

<?php

require_once 'conect.php'; 
        if(isset($_POST['submit'])){

                $nome  = $_POST['nome'];
                $pdo = conexao::getInstance();
                $parametro = Array(':nome'=>'%'.$nome.'%');
                $sql  = ' SELECT * FROM doacao WHERE nome LIKE :nome ';

                try {
                        $stmt = $pdo->prepare($sql);
                        $stmt->bindValue(1, $nome,PDO::PARAM_STR);
                        $stmt->execute($parametro);
                        $resultado = $stmt->FETCH(PDOStatement::fetch());
                } catch (PDOException $e) {
                        echo $e->getMessage();
                }              



              echo '<strong>id:</strong> '       , $resultado->iddoacao       , '<br />';
              echo '<strong>nome:</strong> '     , $resultado->nome      , '<br />';
              echo '<strong>email:</strong> '    , $resultado->descricao    , '<br />';
              echo '<strong>criado em:</strong> ', $resultado->dataentrada , '<br />';
        }

?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
        <title>Read</title>
        <meta charset="iso-8859-1">
</head>
<body>
        <h1>Read</h1>
        <form action="<?php $_SERVER['PHP_SELF'];?>" method="post">
                        <div><label for="nome">Nome</label><input type="text" name="nome" id="nome" /></div>
                        <input type="submit" name="submit" value="Buscar">
        </form>
</body>
</html>

the error that appears:

Fatal error: Uncaught Error: Non-static method Pdostatement::fetch() cannot be called statically in C: xampp htdocs crudread index.php:15 Stack trace: #0 {main} thrown in C: xampp htdocs crudread index.php on line 15.

  • Instead of <code>Pdostatement::fetch()</code> try using <code>PDO::FETCH_ASSOC</code>

  • But I tried with two did not work, maybe I’ll have to change the structure of the array and arrange to work.

  • I noticed you’re running the command $stmt->execute($parametro); instead of running with $stmt->execute($sql);. Would that be?

No answers

Browser other questions tagged

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