CodeIgniter Forums

Full Version: You must use the "set" method to update an entry.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I found several topics related to the error but I couldn't solve it. Below is a screenshot of the error and the code that is showing an error.

CodeIgnter\Views\Header
Code:
<!-- Modal -->
<div class="modal fade" id="signupModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content rounded-0 border-0 p-4">
            <div class="modal-header border-0">
                <h3>Nova Conta</h3>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="login">
                    <form method="post" action="<?=base_url('user/register')?>" class="row">
                        <div class="col-12">
                            <input type="text" class="form-control mb-3" id="userid" name="userid" placeholder="Nome de Usuário">
                        </div>
                        <div class="col-12">
                            <input type="password" class="form-control mb-3" id="user_pass" name="user_pass" placeholder="Senha">
                        </div>
                        <div class="col-12">
                            <input type="password" class="form-control mb-3" id="user_pass_confirm" name="user_pass_confirm" placeholder="Confirmar Senha">
                        </div>
                        <div class="col-12">
                          <select class="form-control mb-3" id="sex" name="sex">
                            <option value="M">Masculino</option>
                            <option value="F">Feminino</option>
                          </select>
                        </div>
                        <div class="col-12">
                            <input type="email" class="form-control mb-3" id="email" name="email" placeholder="E-mail">
                        </div>
                        <div class="col-12">
                            <input type="submit" name="register" class="btn btn-primary" value="REGISTRAR">
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- Modal -->

CodeIgniter\Controllers\User
PHP Code:
<?php namespace App\Controllers;

use 
App\Models\User_model;

class 
User extends BaseController
{
    
    
public function register()
    {
        helper('form');
        $model = new User_model();
        if(!$this->validate([
            'userid' => 'required',
            'user_pass' => 'required'
        ])) {
            echo view('template/header');
            echo view('pages/error');
            echo view('template/footer');
        } else {
            $model->save([
                'userid' => $this->request->getVar('userid'),
                'user_pass' => $this->request->getVar('user_pass'),
                'sex' => $this->request->getVar('sex'),
                'email' => $this->request->getVar('email')
            ]);
            echo view('template/header');
            echo view('pages/success');
            echo view('template/footer');
        }
    }

CodeIgniter\Models\User_model
PHP Code:
<?php namespace App\Models;

use 
CodeIgniter\Model;

class 
User_model extends Model
{
    protected $table 'login';
    protected $primaryKey 'account_id';
    
    
protected $allowedFields = ['userid, user_pass, sex, email'];

    public function getAccount($account_id null)
    {
        if($account_id === null) {
            return $this->findAll();
        }
        return $this->asArray()->where(['account_id' => $account_id])->first();
    }

You don't show what your database looked like, but it is possible a spelling difference between the two will cause this issue.

Although, not affecting you, when using objects, it is important to pass in the correct object, a spelling mistake on the variable name will cause the same error.
The error is for an insert your not showing any insert code.