SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Non-Member
    Join Date
    Oct 2008
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PDO and update? Non-object error

    Hey,

    I'm running this method to reset a password

    PHP Code:
      public function resetPassword($strEmail) {
        if (empty(
    $strEmail))
          return 
    false;
        
        
    $strQuery 'SELECT `name`, `lname`, `email`, `password`
                     FROM customers
                     WHERE email = :email'
    ;
        
    $objStatement $this->DB->prepare($strQuery);
        
    $objStatement->bindParam(':email'$strEmailPDO::PARAM_STR);
        
    $objStatement->execute();
        
        if (
    $row $objStatement->fetch()) {
          
    $strFirstName $row['name'];
          
    $strLastName $row['lname'];
          
          
    $strUnencryptedPassword str_shuffle('MOYZbdejkwxyz3489');
          
    $strNewPassword md5($strUnencryptedPassword);

          
    $strQuery2 'UPDATE customers
                       SET password = :password 
                       WHERE email = :email'
    ;
          
    $objStatement2 $this->DB->prepare($strQuery2);
          
    $objStatement2->bindParam(':password'$strNewPasswordPDO::PARAM_STR);
          
    $objStatement2->bindParam(':email'$strEmailPDO::PARAM_STR);
          if (
    $objStatement2->execute()) {
            
    $strTo $strEmail;
            
    $strSubject 'New Password For site.com'."\n\r";
            
    $strFromName 'site.com'."\n\r";
            
    $strMessage .= 'Hey, '.$strFirstName.' '.$strLastName."\n\r";
            
    $strMessage .= 'You recently requested a new password'."\n\r";
            
    $strMessage .= 'Your new password is: '.$strUnencryptedPassword."\n\r";
            
    $strMessage .= 'Thanks, '."\n\r";
            
    $strMessage .= 'Team'."\n\r";
            
    $headers 'From: noreply@site.com'."\r\n";
            
            if (
    mail($strTo$strSubject$strMessage$headers))
              return 
    true;
          }
          return 
    false;
        }
        return 
    false;
      } 
    Does UPDATE work different for PDO? Because I'm using the same exact syntax for INSERT and SELECT, and it works perfectly.

  2. #2
    SitePoint Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does it give you an actual error code or does it just not work without anything being shown?

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's always a good idea to paste the actual error messages you get. Also, make sure to comment the corresponding lines in the code.

    But, on what you've said, I'm guessing one of your variables, that you think is an object, is really null. You can confirm this by using var_dump() on the variable at the relevant location in the script.

    The above might lead you to need to check if PDO has any errors for you.
    http://www.php.net/manual/en/pdo.errorinfo.php

  4. #4
    Non-Member
    Join Date
    Oct 2008
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks that pdo error is a life saver!


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
  •