How to compare data from two collums?

Hello guys, sry for english. Someone can explain or show example how to compare data from two collums in one table?

I have resetpassword form where user must post his account and email for send resetmail. I need check user post correct email for his account or not.

i am try this in Rules, but not work:

array( ‘login, email’, ‘compare’, ‘compareAttribute’ => (‘login’ == ‘email’), ‘on’=>‘resetpassword’)

Thank you for help.

I believe compare is not the rule to check against, you should use exist rule or right a customer validate function to check if the email exists in the database

// please make sure to change the field/property name to match yours

public function rules()


    return [

        // other rules ...

        ['email', 'exist', 

         'targetClass' => 'app\models\User',

         'message' => 'There is no user with this email address.'




Thank you for help but not work for me… i have yii 1.1+ version

I am rewrite your rule like

array( ‘email’, ‘exist’, ‘className’ => ‘Users’, ‘criteria’ => [‘condition’ => ‘Users::STATUS_ACTIVE’], ‘message’ => ‘There is no user with this email address.’, ‘on’ => ‘resetpassword’ )

cos exist.CExistValidator not have param "filter"

i got error now when fill form

1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘::STATUS_ACTIVE) AND (‘’) LIMIT 1’ at line 1

I have check for correct email from DB

array( ‘email’, ‘exist’, ‘message’ => Yii::t( ‘model’, ‘incorrectEmail’, array( ‘{value}’ => ‘{value}’ ) ), ‘on’ => ‘resetpassword’ )

you can write a customer validator class or validate method

Are you writing a Yii1.1 app to Yii2?

Any way: I don’t think you need to quote the STATUS_ACTIVE condition

['condition' => Users::STATUS_ACTIVE], 

In the Yii2 way in the rules of a requestPasswordReset model:

['email', 'exist',

    'targetClass' => '\common\models\User',

    'filter' => ['is_active' => Users::STATUS_ACTIVE],

    'message' => Yii::t('app', 'There is no user with this email address.')