SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    99
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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
    PHP Code:
     $row $s->fetch(); 

    PHP Code:

    $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.

  2. #2
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    PDOStatement::Execute returns a bool, indicating success. What you want is to get the results in an array. From the php.net manual...

    PHP Code:
    <?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:\n");
    $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.

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    99
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    ok thanks it seems to work!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •