-
pippuccio76 Senior Member
   
-
Posts: 547
Threads: 231
Joined: Jun 2017
Reputation:
2
hi , how can i save the user activation hash on db ?
this is a part of my controller's method :
PHP Code: $post = $this->request->getPost();
// generate random hash for email verification (40 char string) $user_activation_hash = sha1(uniqid(mt_rand(), true));
$post['user_activation_hash'] = $user_activation_hash;
$res=$model->save($post);
every field is stored but user_activation_hash in db are null
-
pippuccio76 Senior Member
   
-
Posts: 547
Threads: 231
Joined: Jun 2017
Reputation:
2
08-21-2020, 06:14 AM
(This post was last modified: 08-21-2020, 06:54 AM by pippuccio76.)
(08-21-2020, 03:54 AM)pippuccio76 Wrote: hi , how can i save the user activation hash on db ?
this is a part of my controller's method :
PHP Code: $post = $this->request->getPost();
// generate random hash for email verification (40 char string) $user_activation_hash = sha1(uniqid(mt_rand(), true));
$post['user_activation_hash'] = $user_activation_hash;
$res=$model->save($post);
every field is stored but user_activation_hash in db are null
Find the error protected $allowedFields user_activation_hash was write bad ...
(08-21-2020, 06:14 AM)pippuccio76 Wrote: (08-21-2020, 03:54 AM)pippuccio76 Wrote: hi , how can i save the user activation hash on db ?
this is a part of my controller's method :
PHP Code: $post = $this->request->getPost();
// generate random hash for email verification (40 char string) $user_activation_hash = sha1(uniqid(mt_rand(), true));
$post['user_activation_hash'] = $user_activation_hash;
$res=$model->save($post);
every field is stored but user_activation_hash in db are null
Find the error protected $allowedFields user_activation_hash was write bad ...
Now i cannot update the data , this is my method inside model :
PHP Code: function confirm_registration($user_activation_hash){
//search user with user_activation_hash=$user_activation_hash $query=$this->where('user_activation_hash', $user_activation_hash)->get();
$user=$query->getRow();
//if ther'arent record if(!$user){
return FALSE; }
$data = array( 'id_stato_users'=>2, 'user_activation_hash' => NULL );
$this->where('id', $user->id); $this->update($data);
if($this->affectedRows()){
return TRUE;
}else{
return FALSE;
}
}
But have this error : There is no data to update. [url=https://www.google.com/search?q=CodeIgniter%5CDatabase%5CExceptions%5CDataException+There+is+no+data+to+update.][/url]
-
InsiteFX Super Moderator
     
-
Posts: 6,728
Threads: 344
Joined: Oct 2014
Reputation:
246
08-21-2020, 12:22 PM
(This post was last modified: 08-21-2020, 12:23 PM by InsiteFX.)
Did you add:
To the model, these are the database field column names.
PHP Code: protected $allowedFields = ['user_activation_hash'];
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
-
pippuccio76 Senior Member
   
-
Posts: 547
Threads: 231
Joined: Jun 2017
Reputation:
2
(08-21-2020, 12:22 PM)InsiteFX Wrote: Did you add:
To the model, these are the database field column names.
PHP Code: protected $allowedFields = ['user_activation_hash'];
Yes:
Code: protected $allowedFields = ['username','email','password','updated_at','deleted_at','last_login','user_activation_hash','condizioni','richiesta_cancellazione','id_stato_users','id_role_users'];
-
pippuccio76 Senior Member
   
-
Posts: 547
Threads: 231
Joined: Jun 2017
Reputation:
2
Dont show error if i change :
$this->update($data);
with :
$this->update('users',$data);
But the values on db aren't update and have the error :
Call to undefined method App\Models\UsersModel::affectedRows
-
InsiteFX Super Moderator
     
-
Posts: 6,728
Threads: 344
Joined: Oct 2014
Reputation:
246
Did you do a var_dump() on it to see if it is getting populated?
PHP Code: var_dump($user_activation_hash);
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
-
pippuccio76 Senior Member
   
-
Posts: 547
Threads: 231
Joined: Jun 2017
Reputation:
2
I find the solution on guide , in work in model now my method is:
PHP Code: function conferma_registrazione($user_activation_hash){
//search user with user_activation_hash=$user_activation_hash $query=$this->where('user_activation_hash', $user_activation_hash)->get();
$user=$query->getRow();
//if ther'arent record if(!$user){
return FALSE; }
$data = [ 'id_stato_users'=>2, 'user_activation_hash' => NULL ];
//$this->where('id', $user->id); $this->update($user->id,$data);
if($this->affectedRows()){
return TRUE;
}else{
return FALSE;
}
}//end conferma registrazione
the solution is in this row :
$this->update($user->id,$data);
first value must be the primaryKey
|