aljosa Posted November 23, 2012 Share Posted November 23, 2012 Hi PHPFreaks Community, I have this PDO method inside class Users for account activation with url click for ex. http://www.mydomainx...16d123f5bbbc3ca which is working O.K. when key is correct but always prints back Activation error3! no matter if UPDATE was SUCCESSFUL or NOT. How can I check If UPDATE was REALLY successful or not and print out correctly? I tried different if statements and I always get the same This is what I have: Class Users: // Activate account after Sign Up public function activate() { try { $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); // Activate account $stmt = $con->prepare("UPDATE `users` SET `active` = NULL, `date` = :date WHERE `active` = :active"); $stmt->execute(array('active' => $_GET['key'], 'date' => date("Y-m-d H:i:s"))); $stmt->execute(); return $stmt->rowCount() ? true : false; } catch ( PDOException $e ) { return $e->getMessage(); } } activate.php if(isset($_SESSION['stat']) == 1) : header('Location:index.html'); else: include_once('includes/config.php'); $errs = ''; $success = ''; if( !(isset( $_GET['key'] ) ) ) { $errs = 'Activation error1.'; } else { if( !(isset( $_GET['key'] ) ) || $_GET['key'] == '' ) { $errs = 'Activation error2.'; } else { $usr = new Users; $usr->storeFormValues( $_GET ); if ($usr->activate() == true) { echo $usr->activate( $_GET ); $success = '<center>Your account is now active. You may now <a href="login.html">Log in</a></center>'; } else { $errs = 'Activation error3.'; } } } Quote Link to comment https://forums.phpfreaks.com/topic/271073-how-to-check-if-pdo-mysql-update-successful/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 23, 2012 Share Posted November 23, 2012 It's because you are executing the query a second time without any data values, which would mean that the WHERE clause is false - $stmt->execute(); Quote Link to comment https://forums.phpfreaks.com/topic/271073-how-to-check-if-pdo-mysql-update-successful/#findComment-1394637 Share on other sites More sharing options...
aljosa Posted November 24, 2012 Author Share Posted November 24, 2012 Thank you Quote Link to comment https://forums.phpfreaks.com/topic/271073-how-to-check-if-pdo-mysql-update-successful/#findComment-1394783 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.