PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, December 30, 2021

[FIXED] Yii deleteAll() records with condition

 December 30, 2021     php, yii     No comments   

Issue

I've set up a log in process where a verification code is generated, and when successful, is then removed. However, i want to make sure that if there's multiple verification codes for the same user, upon log in success, delete all records for that user.

Here's my code

if ($model->validate() && $model->login()) {

    //delete this verification code
    $verificationCode->delete();
    //delete all existing codes for user_id
    VerificationCode::model()->deleteAll('user_id',$user->id);

    Yii::app()->user->setReturnUrl(array('/system/admin/'));

    $this->redirect(Yii::app()->user->returnUrl);
}

However, this seems to just delete all the records, regardless on different user_id's in table. Can anyone see where I'm going wrong?


Solution

Seems you call the function delete() in wrong way ... try passing value this way

VerificationCode::model()->deleteAll('user_id = :user_id', array(':user_id' => $user->id));


Answered By - ScaisEdge
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing