Welcome Guest, Not a member yet? Register   Sign In
Database model to update a field.
#1

(This post was last modified: 10-04-2022, 11:01 PM by davecoventry.)

I'm clearly not understanding how the Database model works.

I have a php script in /App/Models as follows:
PHP Code:
<?php 
namespace App\Models;  
use CodeIgniter\Model;
  
class ProvUserModel extends Model{
 public function 
get_key($key){
    $table='prov_users';
        $builder$this
        
->db
        
->table('prov_users')
            ->select('name, email, password')
            ->where('regkey',$key);
        return $builder->get()->getResult();
    }
 public function 
insert_validated_user($data){
    $table=$this->db->table('users');
    return $table->insert($data[0]);
    }
    public function removeValidationEntry($key){
    $this->db->table('prov_users')
        ->where('regkey'$key)
        ->delete();
    }
 public function 
checkEmail($email){
    return ($this->db->table('users')
        ->where('email',$email)
        ->get()
        ->getResult())?TRUE:FALSE;
    }
 public function 
storePWKey($email,$key){
    $table=$this->db->table('prov_users');
    return ($table->insert(['email' => $email'regkey' => $key]))?TRUE:FALSE;
    }
 public function 
updatePassword($email$pw){
    $val=$this->db->table('users')->where('email',$email)->update(array('password',$pw));
    return $val
    
}
}
?>
All the functions work except for the last function (updatePassword()), which returns false and does not update the table.

My /var/log/mysql/mysql.log looks like this:

Code:
                10017 Query    SET SESSION sql_mode = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
                                        @@sql_mode,
                                        'STRICT_ALL_TABLES,', ''),
                                    ',STRICT_ALL_TABLES', ''),
                                'STRICT_ALL_TABLES', ''),
                            'STRICT_TRANS_TABLES,', ''),
                        ',STRICT_TRANS_TABLES', ''),
                    'STRICT_TRANS_TABLES', '')
                10017 Query    SET NAMES utf8
                10017 Query    SELECT `name`, `email`, `password`
FROM `prov_users`
WHERE `regkey` = 'RbdGGpNliBAgdXWOspn4mjHaOuPNYySctEmZmXfAhsINu7QrMYNLpzThOtYCQuuKTUSHlCfWxv5Cj9whXq5y4T1RZWPXZ8bpsURY'
                10017 Quit
                10018 Query    SET SESSION sql_mode = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
                                        @@sql_mode,
                                        'STRICT_ALL_TABLES,', ''),
                                    ',STRICT_ALL_TABLES', ''),
                                'STRICT_ALL_TABLES', ''),
                            'STRICT_TRANS_TABLES,', ''),
                        ',STRICT_TRANS_TABLES', ''),
                    'STRICT_TRANS_TABLES', '')
                10018 Query    SET NAMES utf8
                10018 Query    UPDATE `users` SET 0 = '$2y$10$f2oAQukoiFKTDR.9yemQTOnTIvw0XM6IzvNteL3scvTmXrB2SVS/G', 1 = 'password'
WHERE `email` = '[email protected]'
                10018 Quit

There is nothing in my /var/log/mysql/error.log

It is quite clear to me that I don't fully understand the mechanism behind the model.
~ Dave
Reply
#2

(This post was last modified: 10-04-2022, 11:47 PM by kenjis.)

PHP Code:
array('password',$pw)

['password' => $pw

See https://codeigniter4.github.io/CodeIgnit...der-update
Reply
#3

(10-04-2022, 11:47 PM)kenjis Wrote:
PHP Code:
array('password',$pw)

['password' => $pw

See https://codeigniter4.github.io/CodeIgnit...der-update

Of course!
~ Dave
Reply




Theme © iAndrew 2016 - Forum software by © MyBB