Fetch() on a non-object

Hey there,

I am dealing with the fetch() on a non-object and not sure why it is displaying this error, well i know why but not sure why (make sense???) it is this line

 $row = $s->fetch();


$query = "SELECT id,farmName,level,salt1,salt2,password FROM users WHERE email = :email";

		$email = $clean->text($_POST['email']);
		$rawPass = $clean->text(hash('sha256',$_POST['password']));

		$values = array('email' => $email);

		try {
		$lookup = $pdo->prepare($query);
		$s = $lookup->execute($values);
			
		} catch (PDOException $e) {
			$message .= "There has been an error trying to login in::: {$e->getMessage()}";
			$title = "Error!";		
		}

		 $row = $s->fetch();
    	if($row[0] > 0){
    		if($row['salt1'].$rawPass.$row['salt2'] == $row['password'])
    		{
        		$_SESSION['email'] = $row['email'];
            	$_SESSION['id'] = $row['id'];
            	$_SESSION['name'] = $row['name'];
            	$_SESSION['level'] = $row['level'];
            	$_SESSION['farmname'] = $row['farmname'];
            }
			$message .=  "You have been logged in!";
			$title = "Logged in!";
            }
        else {
        	$message .= "Password or email was wrong";
        	$title =  "There was an error";
        }


$pdo is defined in a config file that i include.

PDOStatement::Execute returns a bool, indicating success. What you want is to get the results in an array. From the php.net manual…


<?php
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();

/* Fetch all of the remaining rows in the result set */
print("Fetch all of the remaining rows in the result set:\
");
$result = $sth->fetchAll();
print_r($result);
?>

You’re calling fetch() on a bool. So either change your code as above, or call fetch on $lookup, not $s.

ok thanks it seems to work!