Welcome Guest, Not a member yet? Register   Sign In
Models insert() and save() methods return "unknown error" but the query builder works
#1

(This post was last modified: 06-10-2021, 08:28 AM by Polymorphism.)

I'm trying to get user creation functionality working on a signup page. When the form is submitted I use either
Code:
$user->insert($data)
or
Code:
$user->save($data)
. When I call
Code:
$user->error()
it returns "Unknown error" with a code of "101".

If I try to insert the same date using the Query Builder then it works correctly.

Am I using the model class incorrectly?

Here is my code for the method:


PHP Code:
public function create()
 {
        $user = new User();

        $rules = [
            'username' => 'required|min_length[2]|alpha_numeric',
            'email' => 'required|valid_email',
            'password' => 'required',
            'password_confirm' => 'required|matches[password]'
        ];

        /**------------------------------------------------------------------------------
        * Validation
        ------------------------------------------------------------------------------*/
        if (! $this->validate($user->validationRules))
        {
            echo view('login/signup', [
                'validation' => $this->validation,
            ]);
        } else
        {
            $username $this->request->getVar('username');
            $email $this->request->getVar('email');
            $password $this->request->getVar('password');

            $userFound $user->where('username'$username)->first();
            $emailFound $user->where('email'$email)->first();

            $data = [
                'username' => $username,
                'email' => $email,
                'password' => password_hash($passwordPASSWORD_DEFAULT)
            ];

            dump($user->insert($data));
            dump($user->error());

            $this->session->setFlashdata("message""An account for <strong>{$username}</strong> has been created. Now you can login!");
            return redirect()->to('/login');
        
Reply


Messages In This Thread
Models insert() and save() methods return "unknown error" but the query builder works - by Polymorphism - 06-10-2021, 08:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB