Jump to content

How To Check If Pdo Mysql Update Successful?


aljosa

Recommended Posts

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.';
}
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.