User Activation Code doesn't activate after submitting an Update query

I'm working on a project using ZEND

A very strange and non-logical thing keeps on happening.

When user registers it generates an activation code an writes to DB:

//Generate Activation Code;
$activation_code = date('YmdHis');
$activation_code .= substr(number_format(time() * rand(),0,'',''),0,10);

in the database i get for ex. code like this: 201212301653302670595490

User should go to link /user/activation/201212301653302670595490

I get this param with the controller:

public function activateAction() {

$activation_code = htmlentities(trim($this->_getParam('activation_code', 0)));
$activation_code = preg_replace("/[^0-9]/","", $activation_code);

    $usersModel = new Users_Model_DbTable_Users();
    $result = $usersModel->activUser($activation_code);

    if($result) {

        $this->view->message = 'Your account is activated. You may now Login.';

    } else {

        $this->view->message = 'Something went wrong.';


this action calls a function in my models:

public function activUser($activation_code) {

    $data = array(
        'status' => 2

    if($this->update($data, 'activation_code = '. $activation_code)) {
        return true;            


this is the custom rout in my Bootstrap:

$activateUserRoute = new Zend_Controller_Router_Route("user/activate/:activation_code", array(
   'module' => 'users',
   'controller' => 'manage',
   'action' => 'activate'

$router->addRoute('activateUserRoute', $activateUserRoute); 

my cell activation_code in DB table is VARCHAR with Length of 24 ('cuz the generated code in 24 symbols in length).

The awkward moment

it keeps failing the activation process. it always returns false;

if I go to DB, replace generated code with any number 1, 1231231231234 or even the generated code itself (201212301653302670595490) it does the activation.

Maybe you can tell me what's going wrong in here? any practice?


I gotta aske this one first:

What is the point of: $activation_code = preg_replace("/[^0-9]/","", $activation_code); it looks like you are replacing all of the values in your activation code with nothing.

The way you passed the activation code to the $where parameter has been deprecated. In some places that syntax may still work in others it doesn't.

public function activUser($activation_code) {

    $data = array(
        'status' => 2
    $where = $this->getAdapter()->quoteInto('activation_code = ?', $activation_code);
    //update() returns number of rows updated,
    if($this->update($data, $where) === 0) {
        return false;            
    } else {
        return true;

Because update() returns the number of rows updated any untrue condition in your current if() statement would be inaccurate. IT may work correctly most of the time... It would be even better if you tested for exactly the number of rows that are supposed to be updated and fail if that number is not returned.

htmlentities() may not be the best choice to filter your input parameter. You may be much better off filtering for the type of data that you know is there. Zend_Filter_Input has filters and validators that can be very useful.

Try to see SQL that is generated.

Need Your Help

Backslashes in Kornshell

ksh backslash

I was looking over some ksh code and came across a line I didn't think would work. Upon testing the code, it did work, but I am not sure why.

Horizontal UISwipeGestureRecognizer doesn't work for Small UIImageView

ios objective-c uiimageview uigesturerecognizer

I am trying to add a UISwipeGestureRecognizer to a UIImageView located on my UIViewController and it works fine if the frame of the UIImageView is set to the screen bounds. I need the UIImageView m...