문제

I have the below snippet of code. When I run the whole program, it fails at this section with the error Fatal error: Call to a member function fetch() on a non-object in <filename> on line 26. I'm really not sure what I should do to fix the problem. If it matters, I ran the SQL query against my database and it returns exactly what it should.

if(isset($_POST['submit'])) {
        $query = 'SELECT email FROM users WHERE email=:email';
        $query_params = array(':email' => $_POST['email']);

        try {
            $stmt = $conn->prepare($query);
            $result = $stmt->execute($query_params);
        } catch(PDOException $ex) {
            echo $ex->getMessage();
        }

        $row = $result->fetch();   //fails on this line

        if(empty($results)) {
            $passset = 1;
        }
    }
도움이 되었습니까?

해결책

PDOStatement::execute returns TRUE or FALSE, not a result object.

Change this:

$row = $result->fetch();

To this:

$row = $stmt->fetch();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top